bugfixing
This commit is contained in:
parent
cff701ad58
commit
3d9817d138
@ -1255,11 +1255,11 @@ async def get_economic_calendar():
|
|||||||
ny_tz = pytz.timezone('America/New_York')
|
ny_tz = pytz.timezone('America/New_York')
|
||||||
today = datetime.now(ny_tz)
|
today = datetime.now(ny_tz)
|
||||||
|
|
||||||
start_date = (today - timedelta(weeks=4)).strftime("%Y-%m-%d")
|
start_date = (today - timedelta(weeks=2)).strftime("%Y-%m-%d")
|
||||||
end_date = (today + timedelta(weeks=4)).strftime("%Y-%m-%d")
|
end_date = (today + timedelta(weeks=4)).strftime("%Y-%m-%d")
|
||||||
|
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
url = f"https://financialmodelingprep.com/api/v3/economic_calendar?from={start_date}&to={end_date}&apikey={api_key}"
|
url = f"https://financialmodelingprep.com/stable/economic-calendar?from={start_date}&to={end_date}&apikey={api_key}"
|
||||||
async with session.get(url) as response:
|
async with session.get(url) as response:
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
print(f"Fetched data: {len(data)} events")
|
print(f"Fetched data: {len(data)} events")
|
||||||
@ -1268,15 +1268,19 @@ async def get_economic_calendar():
|
|||||||
# Iterate over the fetched data directly
|
# Iterate over the fetched data directly
|
||||||
for item in data:
|
for item in data:
|
||||||
try:
|
try:
|
||||||
matching_country = next((c['short'] for c in country_list if c['long'] == item['country']), None)
|
country = item['country']
|
||||||
print(matching_country)
|
if country == 'USA':
|
||||||
# Special case for USA
|
|
||||||
if item['country'] == 'USA':
|
|
||||||
country_code = 'us'
|
country_code = 'us'
|
||||||
elif matching_country:
|
elif len(country) in (2, 3):
|
||||||
country_code = matching_country.lower()
|
# Assume country is already a code
|
||||||
|
country_code = country.lower()
|
||||||
else:
|
else:
|
||||||
continue
|
# Attempt to match full country name
|
||||||
|
matching_country = next((c['short'] for c in country_list if c['long'].lower() == country.lower()), None)
|
||||||
|
if matching_country:
|
||||||
|
country_code = matching_country.lower()
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
impact = item.get('impact', None)
|
impact = item.get('impact', None)
|
||||||
if impact == 'High':
|
if impact == 'High':
|
||||||
@ -1289,7 +1293,7 @@ async def get_economic_calendar():
|
|||||||
dt = datetime.strptime(item['date'], "%Y-%m-%d %H:%M:%S")
|
dt = datetime.strptime(item['date'], "%Y-%m-%d %H:%M:%S")
|
||||||
filtered_data.append({
|
filtered_data.append({
|
||||||
'countryCode': country_code,
|
'countryCode': country_code,
|
||||||
'country': item['country'],
|
'country': country,
|
||||||
'time': dt.strftime("%H:%M"),
|
'time': dt.strftime("%H:%M"),
|
||||||
'date': dt.strftime("%Y-%m-%d"),
|
'date': dt.strftime("%Y-%m-%d"),
|
||||||
'prior': item['previous'],
|
'prior': item['previous'],
|
||||||
@ -1302,6 +1306,7 @@ async def get_economic_calendar():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error processing item: {e}")
|
print(f"Error processing item: {e}")
|
||||||
|
|
||||||
|
|
||||||
return filtered_data
|
return filtered_data
|
||||||
|
|
||||||
def replace_representative(office):
|
def replace_representative(office):
|
||||||
@ -1662,6 +1667,7 @@ async def save_json_files():
|
|||||||
with open(f"json/economic-calendar/calendar.json", 'w') as file:
|
with open(f"json/economic-calendar/calendar.json", 'w') as file:
|
||||||
ujson.dump(economic_list, file)
|
ujson.dump(economic_list, file)
|
||||||
|
|
||||||
|
|
||||||
stock_screener_data = await get_stock_screener(con)
|
stock_screener_data = await get_stock_screener(con)
|
||||||
with open(f"json/stock-screener/data.json", 'w') as file:
|
with open(f"json/stock-screener/data.json", 'w') as file:
|
||||||
ujson.dump(stock_screener_data, file)
|
ujson.dump(stock_screener_data, file)
|
||||||
@ -1690,7 +1696,6 @@ async def save_json_files():
|
|||||||
ujson.dump(data, file)
|
ujson.dump(data, file)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
con.close()
|
con.close()
|
||||||
etf_con.close()
|
etf_con.close()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user