changed it a bit to keep v6 api, but if v6 don't work, use the v7 workaround
This commit is contained in:
@@ -166,7 +166,7 @@ def updateStocksPrePost(api_key, logf):
|
|||||||
symbols = list(stock_info.keys())
|
symbols = list(stock_info.keys())
|
||||||
|
|
||||||
#KEEP THIS JUST IN CASE V7 GOES DOWN prepost_url = 'https://query2.finance.yahoo.com/v6/finance/quote?symbols='
|
#KEEP THIS JUST IN CASE V7 GOES DOWN prepost_url = 'https://query2.finance.yahoo.com/v6/finance/quote?symbols='
|
||||||
prepost_url = 'https://query2.finance.yahoo.com/v7/finance/quote?symbols='
|
prepost_url = 'https://query2.finance.yahoo.com/v6/finance/quote?symbols='
|
||||||
for symbol in symbols:
|
for symbol in symbols:
|
||||||
prepost_url += symbol + ','
|
prepost_url += symbol + ','
|
||||||
|
|
||||||
@@ -175,6 +175,8 @@ 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',
|
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'}
|
'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()
|
||||||
|
if "'error': {'code'" in str(prepost):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
with open('session.txt', 'rb') as f:
|
with open('session.txt', 'rb') as f:
|
||||||
@@ -189,17 +191,13 @@ def updateStocksPrePost(api_key, logf):
|
|||||||
crumb = f.read()
|
crumb = f.read()
|
||||||
params = {'crumb': crumb}
|
params = {'crumb': crumb}
|
||||||
|
|
||||||
prepost = session.get(prepost_url, headers=headers, params=params).json()
|
prepost = session.get(prepost_url.replace('v6','v7'), headers=headers, params=params).json()
|
||||||
|
|
||||||
if 'Unauthorized' not in str(prepost):
|
if "'error': {'code'" not in str(prepost):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
getCookiesnCrumb()
|
getCookiesnCrumb()
|
||||||
time.sleep(2)
|
time.sleep(5)
|
||||||
|
|
||||||
# prepost = requests.get(prepost_url, headers=headers)
|
|
||||||
# if 'Unauthorized' in str(prepost.json()):
|
|
||||||
# prepost = requests.get(prepost_url.replace('v7','v6'), headers=headers)
|
|
||||||
|
|
||||||
prepost_data = prepost['quoteResponse']['result']
|
prepost_data = prepost['quoteResponse']['result']
|
||||||
time_now = datetime.now(pytz.timezone('America/New_York')).strftime("%H:%M EST")
|
time_now = datetime.now(pytz.timezone('America/New_York')).strftime("%H:%M EST")
|
||||||
|
Reference in New Issue
Block a user