From 3b1c5a7d55314369083e1ab8ebc7fdc2f0031de8 Mon Sep 17 00:00:00 2001 From: Justin Date: Mon, 24 Jul 2023 17:11:04 +0800 Subject: [PATCH] try and except statements added --- database_caller.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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)