diff --git a/telegram_bot/bot_scheduler.py b/telegram_bot/bot_scheduler.py index e69de29..8fcef6f 100644 --- a/telegram_bot/bot_scheduler.py +++ b/telegram_bot/bot_scheduler.py @@ -0,0 +1,37 @@ +""" +script for regularly sending updates on shares and news based on user interval +""" +__author__ = "Florian Kellermann, Linus Eickhoff" +__date__ = "05.04.2022" +__version__ = "0.0.1" +__license__ = "None" + +import shares.share_fetcher as share_fetcher +import news.news_fetcher as news_fetcher + +import datetime +import sys +from apscheduler.schedulers.blocking import BlockingScheduler + +''' +* * * * * code +┬ ┬ ┬ ┬ ┬ +│ │ │ │ │ +│ │ │ │ └──── weekday (0->Monday, 7->Sunday) +│ │ │ └────── Month (1-12) +│ │ └──────── Day (1-31) +│ └────────── Hour (0-23) +└──────────── Minute (0-59) + +example 0 8 * * * -> daily update at 8am +''' + +def user_updates(): + """sends timed updates automatically to user + + Args: + + Returns: + + """ + return \ No newline at end of file diff --git a/telegram_bot/news/news_fetcher.py b/telegram_bot/news/news_fetcher.py index 2b79721..96f50ff 100644 --- a/telegram_bot/news/news_fetcher.py +++ b/telegram_bot/news/news_fetcher.py @@ -20,9 +20,13 @@ load_dotenv() # Init api_key = os.getenv('NEWS_API_KEY') newsapi = NewsApiClient(api_key=api_key) -source_json = requests.get(f"https://newsapi.org/v2/top-headlines/sources?apiKey={api_key}&language=en").json() -sources = source_json["sources"] -str_sources = ",".join([source["id"] for source in sources]) +try: + source_json = requests.get(f"https://newsapi.org/v2/top-headlines/sources?apiKey={api_key}&language=en").json() + sources = source_json["sources"] + str_sources = ",".join([source["id"] for source in sources]) +except KeyError: + print("Error: Could not get sources") + sys.exit(1) def get_all_news_by_keyword(keyword, from_date="2000-01-01"):