diff --git a/app/main.py b/app/main.py index b13c02f..fe1d1e9 100755 --- a/app/main.py +++ b/app/main.py @@ -2677,16 +2677,30 @@ async def get_price_analysis(data:TickerData): cache_key = f"price-analysis-{ticker}" cached_result = redis_client.get(cache_key) if cached_result: - return ujson.loads(cached_result) + return StreamingResponse( + io.BytesIO(cached_result), + media_type="application/json", + headers={"Content-Encoding": "gzip"} + ) try: with open(f"json/price-analysis/{ticker}.json", 'r') as file: res = ujson.load(file) except: res = {} - redis_client.set(cache_key, ujson.dumps(res)) + data = ujson.dumps(res).encode('utf-8') + compressed_data = gzip.compress(data) + + redis_client.set(cache_key, compressed_data) redis_client.expire(cache_key, 3600*3600) # Set cache expiration time to 1 day - return res + + return StreamingResponse( + io.BytesIO(compressed_data), + media_type="application/json", + headers={"Content-Encoding": "gzip"} + ) + + @app.post("/fundamental-predictor-analysis") async def get_fundamental_predictor_analysis(data:TickerData): @@ -2825,7 +2839,7 @@ async def get_politician_stats(data:PoliticianId): @app.get("/all-politicians") async def get_all_politician(): - ''' + cache_key = f"all-politician" cached_result = redis_client.get(cache_key) if cached_result: @@ -2834,7 +2848,7 @@ async def get_all_politician(): media_type="application/json", headers={"Content-Encoding": "gzip"} ) - ''' + try: with open(f"json/congress-trading/search_list.json", 'r') as file: @@ -2845,8 +2859,8 @@ async def get_all_politician(): data = ujson.dumps(res_list).encode('utf-8') compressed_data = gzip.compress(data) - #redis_client.set(cache_key, compressed_data) - #redis_client.expire(cache_key, 3600*3600) # Set cache expiration time to 1 day + redis_client.set(cache_key, compressed_data) + redis_client.expire(cache_key, 3600*3600) # Set cache expiration time to 1 day return StreamingResponse( io.BytesIO(compressed_data), diff --git a/requirements.txt b/requirements.txt index ecd7fa4..884ae86 100755 --- a/requirements.txt +++ b/requirements.txt @@ -34,4 +34,5 @@ backtesting ujson faker finnhub-python -intrinio_sdk \ No newline at end of file +intrinio_sdk +openai \ No newline at end of file