diff --git a/telegram_bot/news/news_fetcher.py b/telegram_bot/news/news_fetcher.py index f913257..332dafd 100644 --- a/telegram_bot/news/news_fetcher.py +++ b/telegram_bot/news/news_fetcher.py @@ -36,7 +36,26 @@ def get_all_news_by_keyword(keyword, from_date="2000-01-01"): # hard coded will JSON/dict: dict containing articles """ top_headlines = newsapi.get_everything(q=keyword, sources=str_sources, language='en', from_param=from_date) - return top_headlines + if(top_headlines["status"] == "ok"): + return top_headlines + else: + return None + + +def get_top_news_by_keyword(keyword): + """get top news to keyword + Args: + keyword (String): keyword for search + + Returns: + JSON/dict: dict containing articles + """ + top_headlines = newsapi.get_top_headlines(q=keyword, sources=str_sources, language='en') + if(top_headlines["status"] == "ok"): + return top_headlines + else: + return None + def format_article(article): """format article for messaging (using markdown syntax)