diff --git a/app/main.py b/app/main.py index fe1d1e9..c238cca 100755 --- a/app/main.py +++ b/app/main.py @@ -11,6 +11,7 @@ from datetime import datetime, timedelta import numpy as np import pandas as pd import ujson +import orjson import aiohttp import pytz import redis @@ -894,6 +895,7 @@ async def economic_calendar(): headers={"Content-Encoding": "gzip"} ) + @app.get("/earnings-calendar") async def earnings_calendar(): @@ -905,19 +907,15 @@ async def earnings_calendar(): media_type="application/json", headers={"Content-Encoding": "gzip"} ) - try: - with open(f"json/earnings-calendar/calendar.json", 'r') as file: - res = ujson.load(file) + with open(f"json/earnings-calendar/calendar.json", 'rb') as file: + res = orjson.loads(file.read()) except: res = [] - - res = ujson.dumps(res).encode('utf-8') + res = orjson.dumps(res) compressed_data = gzip.compress(res) - redis_client.set(cache_key, compressed_data) redis_client.expire(cache_key, 3600 * 24) # Set cache expiration time to 1 day - return StreamingResponse( io.BytesIO(compressed_data), media_type="application/json", @@ -3111,4 +3109,4 @@ async def get_clinical_trial(data:TickerData): io.BytesIO(compressed_data), media_type="application/json", headers={"Content-Encoding": "gzip"} - ) + ) \ No newline at end of file diff --git a/app/restart_json.py b/app/restart_json.py index a9f70a2..205912b 100755 --- a/app/restart_json.py +++ b/app/restart_json.py @@ -265,9 +265,9 @@ async def get_earnings_calendar(con, symbols): url = f"https://financialmodelingprep.com/api/v3/earning_calendar?from={start_date}&to={end_date}&apikey={api_key}" async with session.get(url) as response: data = await response.json() - filtered_data = [{k: v for k, v in stock.items() if stock['symbol'] in symbols and '.' not in stock['symbol']} for stock in data] + filtered_data = [{k: v for k, v in stock.items() if stock['symbol'] in symbols and '.' not in stock['symbol'] and '-' not in stock['symbol']} for stock in data] #filtered_data = [entry for entry in filtered_data if entry] - + print(filtered_data) for entry in filtered_data: try: symbol = entry['symbol'] @@ -301,7 +301,7 @@ async def get_earnings_calendar(con, symbols): print(e) if symbol is None or symbol not in seen_symbols: - #bug in fmp endpoint. Double check that earnigns date is the same as in quote endpoint + #bug in fmp endpoint. Double check that earnings date is the same as in quote endpoint if item['date'] == earnings_date: #print(symbol, item['date'], earnings_date) unique_data.append(item) @@ -1170,6 +1170,11 @@ async def save_json_files(): crypto_symbols = [row[0] for row in crypto_cursor.fetchall()] + earnings_list = await get_earnings_calendar(con,symbols) + with open(f"json/earnings-calendar/calendar.json", 'w') as file: + ujson.dump(earnings_list, file) + + data = await get_most_shorted_stocks(con) with open(f"json/most-shorted-stocks/data.json", 'w') as file: ujson.dump(data, file) @@ -1183,10 +1188,6 @@ async def save_json_files(): data = await get_magnificent_seven(con) with open(f"json/magnificent-seven/data.json", 'w') as file: ujson.dump(data, file) - - earnings_list = await get_earnings_calendar(con,symbols) - with open(f"json/earnings-calendar/calendar.json", 'w') as file: - ujson.dump(earnings_list, file) data = await get_ipo_calendar(con, symbols) with open(f"json/ipo-calendar/data.json", 'w') as file: @@ -1250,7 +1251,7 @@ async def save_json_files(): stock_screener_data = await get_stock_screener(con,symbols) with open(f"json/stock-screener/data.json", 'w') as file: ujson.dump(stock_screener_data, file) - + con.close() @@ -1262,4 +1263,4 @@ try: loop = asyncio.get_event_loop() loop.run_until_complete(save_json_files()) except Exception as e: - print(e) + print(e) \ No newline at end of file