diff --git a/database_caller.py b/database_caller.py index dc7166a..0d67ddd 100755 --- a/database_caller.py +++ b/database_caller.py @@ -72,12 +72,14 @@ def updateStocks(api_key): stock_info = {} 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) + for symbol in symbols: + 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) all_stocks_settings['symbols'] = stock_info - + json.dump(all_stocks_settings, open('csv/stocks_settings.json', 'w+')) @@ -125,13 +127,16 @@ def updateCrypto(api_key): coin_info = {} 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']} - + for sb in symbol_base: + for i,d in enumerate(data): + + symbol = d['symbol'] + base = d['currency'] + + 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 json.dump(all_crypto_settings, open('csv/crypto_settings.json', 'w+')) @@ -180,10 +185,10 @@ def updateForex(api_key): if len(data) > 0: 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']} + for sb in symbol_base: + 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']}