diff --git a/database_caller.py b/database_caller.py index aa14f14..4fd8519 100755 --- a/database_caller.py +++ b/database_caller.py @@ -176,8 +176,10 @@ def updateStocks(api_key, logf): data = response.json() if len(data) > 0: for symbol in symbols: - stock_info[data[symbol]['quote']['symbol']] = {'current': data[symbol]['quote']['latestPrice'], 'change': data[symbol]['quote']['change'], 'percent_change':data[symbol]['quote']['changePercent'] * 100} - + try: + stock_info[data[symbol]['quote']['symbol']] = {'current': data[symbol]['quote']['latestPrice'], 'change': data[symbol]['quote']['change'], 'percent_change':data[symbol]['quote']['changePercent'] * 100} + except: + pass all_stocks_settings['symbols'] = stock_info with open('csv/stocks_settings.json', 'w+') as f: json.dump(all_stocks_settings, f) @@ -211,10 +213,12 @@ def updateStocks(api_key, logf): # stock_info = {} if len(data) > 0: for symbol in symbols: - for stock in data['quoteResponse']['result']: - if stock['symbol'] == symbol: - stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')] = {'current': stock['regularMarketPrice'], 'change': stock['regularMarketChange'], 'percent_change':stock['regularMarketChangePercent']} - + try: + for stock in data['quoteResponse']['result']: + if stock['symbol'] == symbol: + stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')] = {'current': stock['regularMarketPrice'], 'change': stock['regularMarketChange'], 'percent_change':stock['regularMarketChangePercent']} + except: + pass all_stocks_settings['symbols'] = stock_info with open('csv/stocks_settings.json', 'w+') as f: json.dump(all_stocks_settings, f)