From e26f27eb3817e5db1250aeca8e8d9ec83ed29a4e Mon Sep 17 00:00:00 2001 From: Justin Date: Mon, 24 Jul 2023 17:29:31 +0800 Subject: [PATCH] .replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B') for prepost --- database_caller.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/database_caller.py b/database_caller.py index d62debf..76ae2cb 100755 --- a/database_caller.py +++ b/database_caller.py @@ -253,7 +253,7 @@ def updateStocksPrePost(api_key, logf): headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'} - prepost = requests.get(prepost_url, headers=headers).json() + prepost = requests.get(prepost_url.replace('BRK.A', 'BRK-A').replace('BRK.B', 'BRK-B'), headers=headers).json() if "'error': {'code'" in str(prepost): while True: try: @@ -269,7 +269,7 @@ def updateStocksPrePost(api_key, logf): crumb = f.read() params = {'crumb': crumb} - prepost = session.get(prepost_url.replace('v6','v7'), headers=headers, params=params).json() + prepost = session.get(prepost_url.replace('v6','v7').replace('BRK.A', 'BRK-A').replace('BRK.B', 'BRK-B'), headers=headers, params=params).json() if "'error': {'code'" not in str(prepost): break @@ -286,24 +286,24 @@ def updateStocksPrePost(api_key, logf): if stock['symbol'] == symbol: stock_info[stock['symbol']] = {"time_now":time_now} try: - stock_info[stock['symbol']]['Pre-market'] = {'preprice': '%.2f' % stock['preMarketPrice'], + stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')]['Pre-market'] = {'preprice': '%.2f' % stock['preMarketPrice'], 'prechange': '%.2f' % stock['preMarketChange'], 'prepercent': '%.2f' % stock['preMarketChangePercent']} except: try: - stock_info[stock['symbol']]['Pre-market'] = {'preprice': '%.2f' % stock['postMarketPrice'], + stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')]['Pre-market'] = {'preprice': '%.2f' % stock['postMarketPrice'], 'prechange': '%.2f' % 0, 'prepercent': '%.2f' % 0} except: - stock_info[stock['symbol']]['Pre-market'] = {'preprice': '%.2f' % stock['regularMarketPrice'], + stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')]['Pre-market'] = {'preprice': '%.2f' % stock['regularMarketPrice'], 'prechange': '%.2f' % 0, 'prepercent': '%.2f' % 0} try: - stock_info[stock['symbol']]['Post-market'] = {'postprice': '%.2f' % stock['postMarketPrice'], + stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')]['Post-market'] = {'postprice': '%.2f' % stock['postMarketPrice'], 'postchange': '%.2f' % stock['postMarketChange'], 'postpercent': '%.2f' % stock['postMarketChangePercent']} except: - stock_info[stock['symbol']]['Post-market'] = {'postprice': '%.2f' % stock['regularMarketPrice'], + stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')]['Post-market'] = {'postprice': '%.2f' % stock['regularMarketPrice'], 'postchange': '%.2f' % 0, 'postpercent': '%.2f' % 0}