bugfixing
This commit is contained in:
parent
11b172209a
commit
f436590a1f
@ -1251,6 +1251,7 @@ async def get_stock_splits_calendar(con,symbols):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def get_economic_calendar():
|
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)
|
||||||
@ -1265,38 +1266,32 @@ async def get_economic_calendar():
|
|||||||
print(f"Fetched data: {len(data)} events")
|
print(f"Fetched data: {len(data)} events")
|
||||||
|
|
||||||
filtered_data = []
|
filtered_data = []
|
||||||
# Iterate over the fetched data directly
|
|
||||||
for item in data:
|
for item in data:
|
||||||
try:
|
try:
|
||||||
country = item['country']
|
country = item['country']
|
||||||
if country == 'USA':
|
if country == 'USA' or country == 'US':
|
||||||
country_code = 'us'
|
|
||||||
elif country == 'US':
|
|
||||||
country_code = 'us'
|
country_code = 'us'
|
||||||
elif len(country) in (2, 3):
|
elif len(country) in (2, 3):
|
||||||
# Assume country is already a code
|
|
||||||
country_code = country.lower()
|
country_code = country.lower()
|
||||||
else:
|
else:
|
||||||
# Attempt to match full country name
|
|
||||||
matching_country = next((c['short'] for c in country_list if c['long'].lower() == country.lower()), None)
|
matching_country = next((c['short'] for c in country_list if c['long'].lower() == country.lower()), None)
|
||||||
if matching_country:
|
if matching_country:
|
||||||
country_code = matching_country.lower()
|
country_code = matching_country.lower()
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
impact = item.get('impact', None)
|
|
||||||
if impact == 'High':
|
|
||||||
importance = 3
|
|
||||||
elif impact == 'Medium':
|
|
||||||
importance = 2
|
|
||||||
else:
|
|
||||||
importance = 1
|
|
||||||
|
|
||||||
dt = datetime.strptime(item['date'], "%Y-%m-%d %H:%M:%S")
|
impact = item.get('impact', None)
|
||||||
|
importance = 3 if impact == 'High' else 2 if impact == 'Medium' else 1
|
||||||
|
|
||||||
|
# Convert to UTC
|
||||||
|
dt_ny = ny_tz.localize(datetime.strptime(item['date'], "%Y-%m-%d %H:%M:%S")) # Assume given time is NY time
|
||||||
|
dt_utc = dt_ny.astimezone(pytz.UTC) # Convert to UTC
|
||||||
|
|
||||||
filtered_data.append({
|
filtered_data.append({
|
||||||
'countryCode': country_code,
|
'countryCode': country_code,
|
||||||
'country': country,
|
'country': country,
|
||||||
'time': dt.strftime("%H:%M"),
|
'time': dt_utc.strftime("%H:%M"), # UTC Time
|
||||||
'date': dt.strftime("%Y-%m-%d"),
|
'date': dt_utc.strftime("%Y-%m-%d"), # UTC Date
|
||||||
'prior': item['previous'],
|
'prior': item['previous'],
|
||||||
'consensus': item['estimate'],
|
'consensus': item['estimate'],
|
||||||
'actual': item['actual'],
|
'actual': item['actual'],
|
||||||
@ -1307,9 +1302,9 @@ 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):
|
||||||
replacements = {
|
replacements = {
|
||||||
'Knott, Brad (Senator)': 'Brad Knott',
|
'Knott, Brad (Senator)': 'Brad Knott',
|
||||||
@ -1669,7 +1664,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)
|
||||||
@ -1698,6 +1693,7 @@ 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