Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Skipped64-inf committed Apr 13, 2022
1 parent 9fc264c commit b0ec32e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion welcome/src/datasources.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,25 @@ def get_API_Key(key):


def get_news_data(category,all_news=False):


#API info
url = "https://free-news.p.rapidapi.com/v1/search"
headers = {
'x-rapidapi-host': "free-news.p.rapidapi.com",
'x-rapidapi-key': get_API_Key('RAPID_KEY')
}

#check if briefing or news route
if not all_news:
#select random category from list
category = random.choice(category)
querystring = {"q":category,"lang":"de"}


response = requests.request("GET", url, headers=headers, params=querystring)
text = json.loads(response.text)

#check API response & Filter answers
if not response.ok:
return (f"{category}: Keine Neuigkeiten.")
elif not 'articles' in text:
Expand All @@ -41,8 +45,10 @@ def get_news_data(category,all_news=False):

return(f"{category}: {text['title']} ({text['author']}).")

#if /news route
if all_news:
answer = "Hier sind die heutigen News: \n"
#get info for every category
for cat in category:
time.sleep(1)
querystring = {"q":cat,"lang":"de"}
Expand Down

0 comments on commit b0ec32e

Please sign in to comment.