bugfixing
This commit is contained in:
parent
171708b994
commit
12c37c1fe7
@ -373,14 +373,26 @@ async def get_analyst_report():
|
|||||||
|
|
||||||
async def get_latest_wiim():
|
async def get_latest_wiim():
|
||||||
url = "https://api.benzinga.com/api/v2/news"
|
url = "https://api.benzinga.com/api/v2/news"
|
||||||
querystring = {"token": benzinga_api_key,"dateFrom":yesterday,"dateTo":today,"sort":"created:desc", "pageSize": 1000, "channels":"WIIM"}
|
querystring = {
|
||||||
|
"token": benzinga_api_key,
|
||||||
|
"dateFrom": yesterday,
|
||||||
|
"dateTo": today,
|
||||||
|
"sort": "updated:desc",
|
||||||
|
"pageSize": 1000,
|
||||||
|
"channels": "WIIM"
|
||||||
|
}
|
||||||
|
max_retries = 3
|
||||||
|
retry_delay = 2 # seconds
|
||||||
res_list = []
|
res_list = []
|
||||||
|
|
||||||
|
for attempt in range(max_retries):
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
|
|
||||||
async with session.get(url, params=querystring, headers=headers) as response:
|
async with session.get(url, params=querystring, headers=headers) as response:
|
||||||
data = ujson.loads(await response.text())
|
if response.status != 200:
|
||||||
|
await asyncio.sleep(retry_delay)
|
||||||
|
continue
|
||||||
|
|
||||||
|
data = ujson.loads(await response.text())
|
||||||
for item in data:
|
for item in data:
|
||||||
try:
|
try:
|
||||||
if len(item['stocks']) == 1:
|
if len(item['stocks']) == 1:
|
||||||
@ -390,15 +402,28 @@ async def get_latest_wiim():
|
|||||||
quote_data = ujson.load(file)
|
quote_data = ujson.load(file)
|
||||||
item['marketCap'] = quote_data.get('marketCap', None)
|
item['marketCap'] = quote_data.get('marketCap', None)
|
||||||
|
|
||||||
res_list.append({'date': item['created'], 'text': item['title'], 'marketCap': item['marketCap'],'ticker': item['ticker']})
|
res_list.append({
|
||||||
|
'date': item['created'],
|
||||||
|
'text': item['title'],
|
||||||
|
'marketCap': item['marketCap'],
|
||||||
|
'ticker': item['ticker']
|
||||||
|
})
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if res_list:
|
||||||
|
break # Exit retry loop if data is fetched successfully
|
||||||
|
|
||||||
|
if res_list:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
await asyncio.sleep(retry_delay)
|
||||||
|
|
||||||
res_list = sorted(
|
res_list = sorted(
|
||||||
res_list,
|
res_list,
|
||||||
key=lambda item: datetime.strptime(item['date'], '%a, %d %b %Y %H:%M:%S %z'),
|
key=lambda item: datetime.strptime(item['date'], '%a, %d %b %Y %H:%M:%S %z'),
|
||||||
reverse=True
|
reverse=True
|
||||||
)
|
)
|
||||||
|
|
||||||
return res_list[:10]
|
return res_list[:10]
|
||||||
|
|
||||||
async def run():
|
async def run():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user