try and except statements added
This commit is contained in:
parent
8e7d19b2a0
commit
3b1c5a7d55
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user