.replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B') for prepost

This commit is contained in:
Justin 2023-07-24 17:29:31 +08:00 committed by GitHub
parent 0ea3abf9d0
commit e26f27eb38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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}