news settings added

This commit is contained in:
Neythen Treloar
2022-02-24 19:42:33 +00:00
parent 90fe3937bb
commit 9a26c33779
5 changed files with 34 additions and 22 deletions

View File

@@ -204,23 +204,31 @@ def updateNews(api_key):
#'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/news?country=GB'
#'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/news?lang=en'
max_per_cat = 10
try:
all_settings = json.load(open('csv/news_settings.json', 'r'))
url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/news?country={}'.format(all_settings['country'])
if all_settings['use_country']:
if all_settings['country'] == 'Worldwide':
url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/news_worldwide'
else:
c_dict = {'United States':'US', 'Australia':'AU', 'Canada': 'CA', 'Great Britain':'GB', 'New Zealand':'NZ', 'Ireland':'IE', 'Singapore':'SG', 'South Africa': 'ZA'}
cc = c_dict[all_settings['country']]
url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/news?country={}'.format(cc)
elif all_settings['use_category']:
url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/news?category={}'.format(all_settings['category'])
url += '&apiKey=' + api_key
response = requests.get(url)
data = response.json()
print(data)
max_headlines = int(all_settings['num_headlines'])
#load user settings
headlines = data
headlines = data[:max_headlines]
headline_sources = [headline['source'] for headline in headlines]
@@ -571,8 +579,7 @@ if __name__ == '__main__':
api_keys = f.readlines()
api_key = api_keys[0].strip()
try:
weather_key = api_keys[1].strip()
except Exception as e: