From 9a26c33779b6740f354a973b39870d4b15c69fe7 Mon Sep 17 00:00:00 2001 From: Neythen Treloar Date: Thu, 24 Feb 2022 19:42:33 +0000 Subject: [PATCH] news settings added --- database_caller.py | 23 +++++++++++++++-------- server.py | 7 +++++-- setup_config_files.sh | 2 +- static/app.js | 18 ++++++++++-------- templates/index.html | 6 +++--- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/database_caller.py b/database_caller.py index 88e6f3f..db0cac5 100755 --- a/database_caller.py +++ b/database_caller.py @@ -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: diff --git a/server.py b/server.py index 6a30aa5..9cbd2ef 100755 --- a/server.py +++ b/server.py @@ -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+')) diff --git a/setup_config_files.sh b/setup_config_files.sh index 4080692..cddb7ee 100755 --- a/setup_config_files.sh +++ b/setup_config_files.sh @@ -34,7 +34,7 @@ echo '{"feature": "Custom Messages", "speed": "Medium", "animation": "down", "ti echo '{"feature": "Sports (Upcoming Games)", "speed": "medium", "animation": "down", "title": true, "leagues": {"NFL": [{"date": "2021-11-22", "time": "01:20:00", "round": "11", "home_team": "Los Angeles Chargers", "home_score": "41", "away_team": "Pittsburgh Steelers", "away_score": "37"}, {"date": "2021-11-23", "time": "01:15:00", "round": "11", "home_team": "Tampa Bay Buccaneers", "home_score": "0", "away_team": "New York Giants", "away_score": "0"}, {"date": "2021-11-25", "time": "17:30:00", "round": "12", "home_team": "Detroit Lions", "home_score": null, "away_team": "Chicago Bears", "away_score": null}, {"date": "2021-11-25", "time": "21:30:00", "round": "12", "home_team": "Dallas Cowboys", "home_score": null, "away_team": "Las Vegas Raiders", "away_score": null}, {"date": "2021-11-26", "time": "01:20:00", "round": "12", "home_team": "New Orleans Saints", "home_score": null, "away_team": "Buffalo Bills", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Cincinnati Bengals", "home_score": null, "away_team": "Pittsburgh Steelers", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Houston Texans", "home_score": null, "away_team": "New York Jets", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Indianapolis Colts", "home_score": null, "away_team": "Tampa Bay Buccaneers", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Jacksonville Jaguars", "home_score": null, "away_team": "Atlanta Falcons", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Miami Dolphins", "home_score": null, "away_team": "Carolina Panthers", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "New England Patriots", "home_score": null, "away_team": "Tennessee Titans", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "New York Giants", "home_score": null, "away_team": "Philadelphia Eagles", "away_score": null}, {"date": "2021-11-28", "time": "21:05:00", "round": "12", "home_team": "Denver Broncos", "home_score": null, "away_team": "Los Angeles Chargers", "away_score": null}, {"date": "2021-11-28", "time": "21:25:00", "round": "12", "home_team": "Green Bay Packers", "home_score": null, "away_team": "Los Angeles Rams", "away_score": null}, {"date": "2021-11-28", "time": "21:25:00", "round": "12", "home_team": "San Francisco 49ers", "home_score": null, "away_team": "Minnesota Vikings", "away_score": null}], "NBA": [{"date": "2021-11-22", "time": "01:20:00", "round": "11", "home_team": "Los Angeles Chargers", "home_score": "41", "away_team": "Pittsburgh Steelers", "away_score": "37"}, {"date": "2021-11-23", "time": "01:15:00", "round": "11", "home_team": "Tampa Bay Buccaneers", "home_score": "0", "away_team": "New York Giants", "away_score": "0"}, {"date": "2021-11-25", "time": "17:30:00", "round": "12", "home_team": "Detroit Lions", "home_score": null, "away_team": "Chicago Bears", "away_score": null}, {"date": "2021-11-25", "time": "21:30:00", "round": "12", "home_team": "Dallas Cowboys", "home_score": null, "away_team": "Las Vegas Raiders", "away_score": null}, {"date": "2021-11-26", "time": "01:20:00", "round": "12", "home_team": "New Orleans Saints", "home_score": null, "away_team": "Buffalo Bills", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Cincinnati Bengals", "home_score": null, "away_team": "Pittsburgh Steelers", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Houston Texans", "home_score": null, "away_team": "New York Jets", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Indianapolis Colts", "home_score": null, "away_team": "Tampa Bay Buccaneers", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Jacksonville Jaguars", "home_score": null, "away_team": "Atlanta Falcons", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Miami Dolphins", "home_score": null, "away_team": "Carolina Panthers", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "New England Patriots", "home_score": null, "away_team": "Tennessee Titans", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "New York Giants", "home_score": null, "away_team": "Philadelphia Eagles", "away_score": null}, {"date": "2021-11-28", "time": "21:05:00", "round": "12", "home_team": "Denver Broncos", "home_score": null, "away_team": "Los Angeles Chargers", "away_score": null}, {"date": "2021-11-28", "time": "21:25:00", "round": "12", "home_team": "Green Bay Packers", "home_score": null, "away_team": "Los Angeles Rams", "away_score": null}, {"date": "2021-11-28", "time": "21:25:00", "round": "12", "home_team": "San Francisco 49ers", "home_score": null, "away_team": "Minnesota Vikings", "away_score": null}]}}' >> upcoming_games.json echo '{"feature": "Stocks", "speed": "medium", "animation": "down", "percent": false, "point": false, "logos": true, "chart": false, "title": true, "symbols": {"EUR,USD": {"current": "1.1334", "24hr_change": "-0.0003", "percent_change": "0.00"}, "USD,JPY": {"current": "114.960", "24hr_change": "0.1600", "percent_change": "0.14"}, "GBP,USD": {"current": "1.3577", "24hr_change": "-0.0031", "percent_change": "-0.23"}, "USD,CHF": {"current": "0.9198", "24hr_change": "0.0029", "percent_change": "0.32"}}}' >> forex_settings.json echo '{"speed": "medium", "animation": "down", "title": true, "pause": "2", "images": []}'>> GIF_settings.json -echo '{"feature": "News", "speed": "medium", "animation": "down", "country": "USA", "category": "general", "title": true, "use_sources": true, "sources": [], "headlines": []}' >> news_settings.json +echo '{"feature": "News", "speed": "medium", "animation": "down", "country": "US", "category": "General", "title": true, "headlines": [], "use_category": true, "use_country": false, "num_headlines": "10"}' >> news_settings.json echo '{"speed": "slow", "animation": "down", "title": true, "pause": "/", "images": []}' >> image_settings.json echo '{"feature": "Sports (Past Games)", "speed": "medium", "animation": "down", "title": true, "leagues": {}}' >> past_games.json echo '{"brightness": 10, "country_code": "GB", "hostname": "fintic"}' >> general_settings.json diff --git a/static/app.js b/static/app.js index 12c8f60..a576a69 100755 --- a/static/app.js +++ b/static/app.js @@ -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; } diff --git a/templates/index.html b/templates/index.html index b15765e..e99570a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1564,7 +1564,7 @@