news settings added
This commit is contained in:
@@ -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:
|
||||
|
Reference in New Issue
Block a user