ddtabase caller bugfix
This commit is contained in:
parent
6ceb2e3645
commit
8a535249b4
@ -66,19 +66,20 @@ def updateStocks(api_key):
|
|||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
data = response.json()
|
data = response.json()
|
||||||
print(response)
|
print(response)
|
||||||
print(data)
|
print(dir(response))
|
||||||
|
print(len(data))
|
||||||
|
|
||||||
stock_info = {}
|
stock_info = {}
|
||||||
|
if len(data) > 0:
|
||||||
for stock in data:
|
for stock in data:
|
||||||
stock_info[stock['symbol']] = {'current': stock['price'], 'change': stock['change_since'], 'percent_change':stock['percent']}
|
stock_info[stock['symbol']] = {'current': stock['price'], 'change': stock['change_since'], 'percent_change':stock['percent']}
|
||||||
|
|
||||||
print(stock_info)
|
print(stock_info)
|
||||||
all_stocks_settings['symbols'] = stock_info
|
all_stocks_settings['symbols'] = stock_info
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
json.dump(all_stocks_settings, open('csv/stocks_settings.json', 'w+'))
|
json.dump(all_stocks_settings, open('csv/stocks_settings.json', 'w+'))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
||||||
@ -122,16 +123,17 @@ def updateCrypto(api_key):
|
|||||||
|
|
||||||
|
|
||||||
coin_info = {}
|
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']
|
json.dump(all_crypto_settings, open('csv/crypto_settings.json', 'w+'))
|
||||||
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+'))
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
||||||
@ -174,19 +176,19 @@ def updateForex(api_key):
|
|||||||
data = response.json()
|
data = response.json()
|
||||||
|
|
||||||
|
|
||||||
|
if len(data) > 0:
|
||||||
print(data)
|
print(data)
|
||||||
c_dict = {}
|
c_dict = {}
|
||||||
|
|
||||||
for d in data:
|
for d in data:
|
||||||
|
|
||||||
c_dict[d['uid'].replace('/',',')] = {'current': d['rate'], '24hr_change': d['rate_over_24hr'], 'percent_change':d['percent_over_24hr']}
|
|
||||||
|
|
||||||
|
|
||||||
|
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+' ))
|
|
||||||
|
|
||||||
|
all_forex_settings['symbols'] = c_dict
|
||||||
|
json.dump(all_forex_settings, open( "csv/forex_settings.json", 'w+' ))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
||||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||||
@ -225,22 +227,22 @@ def updateNews(api_key):
|
|||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
data = response.json()
|
data = response.json()
|
||||||
print(data)
|
print(data)
|
||||||
|
if len(data) > 0:
|
||||||
max_headlines = int(all_settings['num_headlines'])
|
max_headlines = int(all_settings['num_headlines'])
|
||||||
#load user settings
|
#load user settings
|
||||||
headlines = data[:max_headlines]
|
headlines = data[:max_headlines]
|
||||||
headline_sources = [headline['source'] for headline in headlines]
|
headline_sources = [headline['source'] for headline in headlines]
|
||||||
|
|
||||||
|
|
||||||
headline_titles = [headline['title'] for headline in headlines]
|
|
||||||
|
headline_titles = [headline['title'] for headline in headlines]
|
||||||
headline_times = [headline['publishedAt'] for headline in headlines]
|
|
||||||
|
headline_times = [headline['publishedAt'] for headline in headlines]
|
||||||
headlines = list(zip(headline_titles, headline_sources, headline_times))
|
|
||||||
print(headlines)
|
headlines = list(zip(headline_titles, headline_sources, headline_times))
|
||||||
all_settings['headlines'] = headlines
|
print(headlines)
|
||||||
|
all_settings['headlines'] = headlines
|
||||||
json.dump(all_settings, open('csv/news_settings.json', 'w+'))
|
|
||||||
|
json.dump(all_settings, open('csv/news_settings.json', 'w+'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
10
server.py
10
server.py
@ -21,15 +21,21 @@ from subprocess import Popen, PIPE
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import copy
|
import copy
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
import sys
|
||||||
#stock_ticker = StockTicker()
|
#stock_ticker = StockTicker()
|
||||||
#print('API CALLER NOT STARTED')
|
#print('API CALLER NOT STARTED')
|
||||||
|
|
||||||
#open('log.txt', 'w').close() #wipe logs
|
#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 api_caller.py")
|
||||||
api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 database_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
|
displaying_screensaver = False
|
||||||
uploading = False
|
uploading = False
|
||||||
screensaver_p = None
|
screensaver_p = None
|
||||||
|
Loading…
Reference in New Issue
Block a user