From 8e7d19b2a0e50f40ca09c399e99668fb615ccb37 Mon Sep 17 00:00:00 2001 From: Justin Date: Mon, 24 Jul 2023 17:02:58 +0800 Subject: [PATCH] try replacing brk a brk b for yfinance --- database_caller.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/database_caller.py b/database_caller.py index b4c2c24..aa14f14 100755 --- a/database_caller.py +++ b/database_caller.py @@ -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: