try replacing brk a brk b for yfinance

This commit is contained in:
Justin 2023-07-24 17:02:58 +08:00 committed by GitHub
parent 7ce1c8973b
commit 8e7d19b2a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -183,6 +183,7 @@ def updateStocks(api_key, logf):
json.dump(all_stocks_settings, f)
elif 'query1.finance.yahoo.com/v7' in url:
url = url.replace('BRK.A', 'BRK-A').replace('BRK.B', 'BRK-B')
response = requests.get(url, headers=headers)
data = response.json()
if "'error': {'code'" in str(data):
@ -212,7 +213,7 @@ def updateStocks(api_key, logf):
for symbol in symbols:
for stock in data['quoteResponse']['result']:
if stock['symbol'] == symbol:
stock_info[stock['symbol']] = {'current': stock['regularMarketPrice'], 'change': stock['regularMarketChange'], 'percent_change':stock['regularMarketChangePercent']}
stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')] = {'current': stock['regularMarketPrice'], 'change': stock['regularMarketChange'], 'percent_change':stock['regularMarketChangePercent']}
all_stocks_settings['symbols'] = stock_info
with open('csv/stocks_settings.json', 'w+') as f: