news settings added
This commit is contained in:
parent
90fe3937bb
commit
9a26c33779
@ -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:
|
||||
|
@ -585,11 +585,14 @@ def save_news_settings(input_settings):
|
||||
current_settings['speed'] = input_settings['speed'].lower()
|
||||
current_settings['animation'] = input_settings['animation'].lower()
|
||||
current_settings['title'] = input_settings['title']
|
||||
current_settings['category'] = input_settings['category'].lower()
|
||||
current_settings['category'] = input_settings['category']
|
||||
current_settings['country'] = input_settings['country']
|
||||
current_settings['use_category'] = input_settings['use_category']
|
||||
current_settings['use_country'] = input_settings['use_country']
|
||||
current_settings['num_headlines'] = input_settings['num_headlines']
|
||||
|
||||
|
||||
current_settings['sources'] = list(set(current_settings['sources'] + input_settings['sources']))
|
||||
|
||||
print(current_settings)
|
||||
|
||||
json.dump(current_settings, open('csv/' + filename, 'w+'))
|
||||
|
File diff suppressed because one or more lines are too long
@ -1170,23 +1170,25 @@ var weatherAPIbtn = document.getElementById("weather-api-btn");
|
||||
weatherAPIbtn.addEventListener("click", saveWeatherAPIKey);
|
||||
|
||||
function getNewsSettings(page) {
|
||||
/*
|
||||
|
||||
let country = getSelected(page.querySelectorAll(".country-select")[0]);
|
||||
let category = getSelected(page.querySelectorAll(".category-select")[0]);
|
||||
let country_check = page.querySelectorAll(".country-check")[0].checked;
|
||||
let category_check = page.querySelectorAll(".category-check")[0].checked;
|
||||
|
||||
let num_headlines = page.querySelectorAll(".headline-num")[0].value
|
||||
let title = page.querySelectorAll(".title-select")[0].checked;
|
||||
// let use_sources = page.querySelectorAll(".sources-select")[0].checked;
|
||||
|
||||
// let sources_el = page.querySelectorAll(".sources-list")[0];
|
||||
// let sources = getListItems(sources_el);
|
||||
settings = {
|
||||
country: country,
|
||||
category: category,
|
||||
use_country: country_check,
|
||||
use_category: category_check,
|
||||
num_headlines: num_headlines,
|
||||
title: title,
|
||||
// use_sources: use_sources,
|
||||
sources: sources,
|
||||
};
|
||||
* */
|
||||
settings = {}
|
||||
|
||||
console.log(settings);
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
@ -1564,7 +1564,7 @@
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<input
|
||||
class="form-check-input title-select news_check_class"
|
||||
class="form-check-input title-select news_check_class country-check"
|
||||
type="checkbox"
|
||||
value=""
|
||||
id="flexCheckChecked30"
|
||||
@ -1595,7 +1595,7 @@
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<input
|
||||
class="form-check-input title-select news_check_class"
|
||||
class="form-check-input title-select news_check_class category-check"
|
||||
type="checkbox"
|
||||
value=""
|
||||
id="flexCheckChecked31"
|
||||
@ -1612,7 +1612,7 @@
|
||||
<div class="col-auto">
|
||||
<select
|
||||
id="inputTransition62"
|
||||
class="form-select category-select"
|
||||
class="form-select category-select headline-num"
|
||||
>
|
||||
<option>10</option>
|
||||
<option>15</option>
|
||||
|
Loading…
Reference in New Issue
Block a user