ddtabase caller bugfix

This commit is contained in:
Neythen Treloar
2022-02-28 16:38:24 +00:00
parent 6ceb2e3645
commit 8a535249b4
2 changed files with 57 additions and 49 deletions

View File

@@ -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+'))