From 643c040b32cefdb180468d606b0e01ca0d7cc742 Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Mon, 4 Apr 2022 18:57:59 +0200 Subject: [PATCH] updated and added functions --- telegram_bot/news/news_fetcher.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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)