diff --git a/database_caller.py b/database_caller.py index dd7a84e..776adca 100755 --- a/database_caller.py +++ b/database_caller.py @@ -66,19 +66,20 @@ def updateStocks(api_key): response = requests.get(url) data = response.json() print(response) - print(data) + print(dir(response)) + print(len(data)) stock_info = {} - - for stock in data: - stock_info[stock['symbol']] = {'current': stock['price'], 'change': stock['change_since'], 'percent_change':stock['percent']} - - print(stock_info) - all_stocks_settings['symbols'] = stock_info - - - - json.dump(all_stocks_settings, open('csv/stocks_settings.json', 'w+')) + if len(data) > 0: + for stock in data: + stock_info[stock['symbol']] = {'current': stock['price'], 'change': stock['change_since'], 'percent_change':stock['percent']} + + print(stock_info) + all_stocks_settings['symbols'] = stock_info + + + + json.dump(all_stocks_settings, open('csv/stocks_settings.json', 'w+')) except Exception as e: @@ -122,16 +123,17 @@ def updateCrypto(api_key): coin_info = {} - for i,d in enumerate(data): #TODO get base from the server + if len(data) > 0: + for i,d in enumerate(data): + + symbol = d['symbol'] + base = d['currency'] + + coin_info[symbol.upper() + ',' + base.upper()] = {'current': d['price'], '24hr_change': d['price_over_24hr'], 'percent_change': d['percent_over_24hr']} + + all_crypto_settings['symbols'] = coin_info - symbol = d['symbol'] - base = d['currency'] - - coin_info[symbol.upper() + ',' + base.upper()] = {'current': d['price'], '24hr_change': d['price_over_24hr'], 'percent_change': d['percent_over_24hr']} - - all_crypto_settings['symbols'] = coin_info - - json.dump(all_crypto_settings, open('csv/crypto_settings.json', 'w+')) + json.dump(all_crypto_settings, open('csv/crypto_settings.json', 'w+')) except Exception as e: @@ -174,19 +176,19 @@ def updateForex(api_key): data = response.json() - - print(data) - c_dict = {} - - for d in data: - - c_dict[d['uid'].replace('/',',')] = {'current': d['rate'], '24hr_change': d['rate_over_24hr'], 'percent_change':d['percent_over_24hr']} - + if len(data) > 0: + print(data) + c_dict = {} + + for d in data: - - - all_forex_settings['symbols'] = c_dict - json.dump(all_forex_settings, open( "csv/forex_settings.json", 'w+' )) + c_dict[d['uid'].replace('/',',')] = {'current': d['rate'], '24hr_change': d['rate_over_24hr'], 'percent_change':d['percent_over_24hr']} + + + + + all_forex_settings['symbols'] = c_dict + json.dump(all_forex_settings, open( "csv/forex_settings.json", 'w+' )) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() @@ -225,22 +227,22 @@ def updateNews(api_key): response = requests.get(url) data = response.json() print(data) - - max_headlines = int(all_settings['num_headlines']) - #load user settings - headlines = data[:max_headlines] - headline_sources = [headline['source'] for headline in headlines] - + if len(data) > 0: + max_headlines = int(all_settings['num_headlines']) + #load user settings + headlines = data[:max_headlines] + headline_sources = [headline['source'] for headline in headlines] - headline_titles = [headline['title'] for headline in headlines] - - headline_times = [headline['publishedAt'] for headline in headlines] - - headlines = list(zip(headline_titles, headline_sources, headline_times)) - print(headlines) - all_settings['headlines'] = headlines - - json.dump(all_settings, open('csv/news_settings.json', 'w+')) + + headline_titles = [headline['title'] for headline in headlines] + + headline_times = [headline['publishedAt'] for headline in headlines] + + headlines = list(zip(headline_titles, headline_sources, headline_times)) + print(headlines) + all_settings['headlines'] = headlines + + json.dump(all_settings, open('csv/news_settings.json', 'w+')) diff --git a/server.py b/server.py index 961aeb6..e693bdd 100755 --- a/server.py +++ b/server.py @@ -21,15 +21,21 @@ from subprocess import Popen, PIPE import numpy as np import copy import urllib.request +import sys #stock_ticker = StockTicker() #print('API CALLER NOT STARTED') #open('log.txt', 'w').close() #wipe logs -os.system("sudo ./check_update.sh") + #api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 api_caller.py") api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 database_caller.py") -api_caller.sendline('A') +time.sleep(3) +api_caller.sendline('s') +#api_caller.sendline('A') +sys.exit() +os.system("sudo ./check_update.sh") + displaying_screensaver = False uploading = False screensaver_p = None