fixed ordering bug

This commit is contained in:
Neythen Treloar 2022-03-01 18:37:41 +00:00
parent d891e5ef6d
commit 4c16217584

View File

@ -72,10 +72,12 @@ def updateStocks(api_key):
stock_info = {} stock_info = {}
if len(data) > 0: if len(data) > 0:
for stock in data: for symbol in symbols:
stock_info[stock['symbol']] = {'current': stock['price'], 'change': stock['change_since'], 'percent_change':stock['percent']} for stock in data:
if stock['symbol'] == symbol:
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
@ -125,12 +127,15 @@ def updateCrypto(api_key):
coin_info = {} coin_info = {}
if len(data) > 0: if len(data) > 0:
for i,d in enumerate(data): for sb in symbol_base:
for i,d in enumerate(data):
symbol = d['symbol'] symbol = d['symbol']
base = d['currency'] base = d['currency']
coin_info[symbol.upper() + ',' + base.upper()] = {'current': d['price'], '24hr_change': d['price_over_24hr'], 'percent_change': d['percent_over_24hr']} if symbol.upper() + ',' + base.upper() == sb:
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 all_crypto_settings['symbols'] = coin_info
@ -180,10 +185,10 @@ def updateForex(api_key):
if len(data) > 0: if len(data) > 0:
print(data) print(data)
c_dict = {} c_dict = {}
for sb in symbol_base:
for d in data: for d in data:
if d['uid'].replace('/',',') == sb:
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']}