Files
hik-push/hik_push/main.py

33 lines
662 B
Python
Raw Normal View History

2024-01-26 11:34:46 +08:00
import json
from redis import asyncio as aioredis
import uvicorn
2024-01-30 17:25:58 +08:00
from fastapi import FastAPI, BackgroundTasks
2024-01-26 11:34:46 +08:00
app = FastAPI()
async def add_stream(data: dict):
redis = await aioredis.Redis(host="127.0.0.1", port=6379)
await redis.lpush("hik-sub-event", json.dumps(data))
await redis.close()
@app.get("/")
async def root():
return {"message": "Hello World"}
@app.post("/eventRcv")
async def event_rcv(data: dict, background_tasks: BackgroundTasks):
background_tasks.add_task(add_stream, data)
return {"msg": "success"}
def run_app():
2024-01-30 17:25:58 +08:00
uvicorn.run(app=app, host="0.0.0.0", port=8000)
2024-01-26 11:34:46 +08:00
if __name__ == "__main__":
run_app()