Dmitry Beresnev commited on
Commit
6c0eb4d
·
1 Parent(s): c639c6c

fix bot for local env

Browse files
Dockerfile CHANGED
@@ -17,6 +17,8 @@ ENV HOME=/home/user \
17
 
18
  ENV PYTHONPATH="$HOME/.local/lib/python3.12/site-packages:$PYTHONPATH"
19
 
 
 
20
  # Set the working directory to the user's home directory
21
  WORKDIR $HOME/app
22
 
@@ -50,4 +52,4 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
50
 
51
  # Run the application
52
  #CMD ["python", "-m", "uvicorn", "src.telegram_bot:app", "--host", "0.0.0.0", "--port", "7860"]
53
- CMD ["python", "-m", "src/telegram_bot.py"]
 
17
 
18
  ENV PYTHONPATH="$HOME/.local/lib/python3.12/site-packages:$PYTHONPATH"
19
 
20
+ ENV PYTHONPATH=/home/user/app/src
21
+
22
  # Set the working directory to the user's home directory
23
  WORKDIR $HOME/app
24
 
 
52
 
53
  # Run the application
54
  #CMD ["python", "-m", "uvicorn", "src.telegram_bot:app", "--host", "0.0.0.0", "--port", "7860"]
55
+ CMD ["python", "-m", "telegram_bot"]
src/financial_news_requester.py CHANGED
@@ -18,7 +18,8 @@ def fetch_comp_financial_news(ticker: str = 'NVDA', date_from = "2025-07-31", da
18
  try:
19
  finnhub_client = finnhub.Client(api_key=api_key)
20
  news_feed = finnhub_client.company_news(ticker, _from=date_from, to=date_to)
21
- logging.info(f'got total amount of news: {news_feed} for ticker: {ticker}')
 
22
  except Exception as e:
23
  logging.info(f"Error fetching financial news: {e}")
24
  return None
 
18
  try:
19
  finnhub_client = finnhub.Client(api_key=api_key)
20
  news_feed = finnhub_client.company_news(ticker, _from=date_from, to=date_to)
21
+ logging.info(f'got total amount of news: {len(news_feed)} for ticker: {ticker}')
22
+ return news_feed
23
  except Exception as e:
24
  logging.info(f"Error fetching financial news: {e}")
25
  return None
src/telegram_bot.py CHANGED
@@ -57,24 +57,30 @@ async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
57
 
58
  async def run_crew(update: Update, context: ContextTypes.DEFAULT_TYPE):
59
  await update.message.reply_text("Fetching latest financial news...")
60
- try:
61
- feed = fetch_comp_financial_news()
62
- logger.info(f"Processed: {len(feed)} news items")
63
-
64
- formatted_news = format_news_for_telegram(feed)
65
-
66
- # Split message if too long (Telegram limit is 4096 characters)
67
- if len(formatted_news) > 4000:
68
- # Send in chunks
69
- chunks = [formatted_news[i:i + 4000] for i in range(0, len(formatted_news), 4000)]
70
- for chunk in chunks:
 
 
71
  await update.message.reply_text(chunk, parse_mode='HTML')
72
- else:
73
- await update.message.reply_text(formatted_news, parse_mode='HTML')
74
-
75
- except Exception as e:
76
- logger.error(f"Error in run_crew: {e}")
77
- await update.message.reply_text(f"Sorry, there was an error fetching news: {str(e)}")
 
 
 
 
78
 
79
 
80
  # Add handlers to the global application
 
57
 
58
  async def run_crew(update: Update, context: ContextTypes.DEFAULT_TYPE):
59
  await update.message.reply_text("Fetching latest financial news...")
60
+ # try:
61
+ feed = fetch_comp_financial_news()
62
+ logger.info(f"Processed: {len(feed)} news items")
63
+
64
+ formatted_news = format_news_for_telegram(feed)
65
+
66
+ # Split message if too long (Telegram limit is 4096 characters)
67
+ if len(formatted_news) > 4000:
68
+ # Split by news items, not by character count
69
+ items = formatted_news.split('\n\n')
70
+ chunk = ""
71
+ for item in items:
72
+ if len(chunk) + len(item) + 2 > 4000:
73
  await update.message.reply_text(chunk, parse_mode='HTML')
74
+ chunk = ""
75
+ chunk += item + "\n\n"
76
+ if chunk:
77
+ await update.message.reply_text(chunk, parse_mode='HTML')
78
+ else:
79
+ await update.message.reply_text(formatted_news, parse_mode='HTML')
80
+
81
+ #except Exception as e:
82
+ # logger.error(f"Error in run_crew: {e}")
83
+ # await update.message.reply_text(f"Sorry, there was an error fetching news: {str(e)}")
84
 
85
 
86
  # Add handlers to the global application