diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index b700e28..0dcf793 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -327,13 +327,13 @@ def send_news(message): top_news = news.get_top_news_by_keyword(keyword)["articles"] if top_news == None: # true if request to NewsAPI failed bot.send_message(chat_id=user_id, text='News Server did not respond correctly. Try again later.') - return + if not top_news: # true if no news found for keyword (empty list) bot.send_message(chat_id=user_id, text=f'No news found for keyword: *{keyword}*', parse_mode="MARKDOWN") - return - - formatted_article = news.format_article(top_news[0]) # only format and send most popular news - bot.send_message(chat_id=user_id, text=f"_keyword: {keyword}_\n\n" + formatted_article, parse_mode="MARKDOWN") + + else: + formatted_article = news.format_article(top_news[0]) # only format and send most popular news + bot.send_message(chat_id=user_id, text=f"_keyword: {keyword}_\n\n" + formatted_article, parse_mode="MARKDOWN") @bot.message_handler(commands=['addkeyword', 'Addkeyword']) # /addkeyword -> add keyword to user