added small error handling

This commit is contained in:
Linus E 2022-04-17 10:49:42 +02:00
parent 1095c63788
commit acdd46780c
2 changed files with 44 additions and 3 deletions

View File

@ -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

View File

@ -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"):