add sentiment tracker endpoint
This commit is contained in:
parent
15fc3fa091
commit
14ad89640e
29
app/main.py
29
app/main.py
@ -3929,6 +3929,35 @@ async def get_fomc_impact(data: TickerData, api_key: str = Security(get_api_key)
|
||||
headers={"Content-Encoding": "gzip"}
|
||||
)
|
||||
|
||||
@app.get("/sentiment-tracker")
|
||||
async def get_fomc_impact(api_key: str = Security(get_api_key)):
|
||||
|
||||
cache_key = f"sentiment-tracker"
|
||||
cached_result = redis_client.get(cache_key)
|
||||
if cached_result:
|
||||
return StreamingResponse(
|
||||
io.BytesIO(cached_result),
|
||||
media_type="application/json",
|
||||
headers={"Content-Encoding": "gzip"}
|
||||
)
|
||||
try:
|
||||
with open(f"json/sentiment-tracker/data.json", 'rb') as file:
|
||||
res = orjson.loads(file.read())
|
||||
except:
|
||||
res = {}
|
||||
|
||||
data = orjson.dumps(res)
|
||||
compressed_data = gzip.compress(data)
|
||||
|
||||
redis_client.set(cache_key, compressed_data)
|
||||
redis_client.expire(cache_key,3600*3600)
|
||||
|
||||
return StreamingResponse(
|
||||
io.BytesIO(compressed_data),
|
||||
media_type="application/json",
|
||||
headers={"Content-Encoding": "gzip"}
|
||||
)
|
||||
|
||||
@app.get("/newsletter")
|
||||
async def get_newsletter():
|
||||
try:
|
||||
|
||||
@ -485,7 +485,8 @@ def run_tracker():
|
||||
"cron_reddit_tracker.py",
|
||||
"cron_reddit_statistics.py",
|
||||
"cron_cramer_tracker.py",
|
||||
"cron_lobbying_tracker.py"
|
||||
"cron_lobbying_tracker.py",
|
||||
"cron_sentiment_tracker.py"
|
||||
]
|
||||
for script in scripts:
|
||||
run_command(["python3", script])
|
||||
@ -494,7 +495,8 @@ def run_tracker():
|
||||
rsync_commands = [
|
||||
("/root/backend/app/json/reddit-tracker", "/root/backend/app/json"),
|
||||
("/root/backend/app/json/cramer-tracker", "/root/backend/app/json"),
|
||||
("/root/backend/app/json/corporate-lobbying/tracker", "/root/backend/app/json/corporate-lobbying")
|
||||
("/root/backend/app/json/corporate-lobbying/tracker", "/root/backend/app/json/corporate-lobbying"),
|
||||
("/root/backend/app/json/sentiment-tracker", "/root/backend/app/json")
|
||||
]
|
||||
|
||||
base_command = ["sudo", "rsync", "-avz", "-e", "ssh"]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user