diff --git a/xumu.py b/xumu.py index aa79509..11b8c57 100644 --- a/xumu.py +++ b/xumu.py @@ -1,8 +1,7 @@ import re -import time import json from typing import Any - +from datetime import datetime, timedelta import requests import uvicorn from fastapi import FastAPI, Request @@ -327,5 +326,23 @@ async def process_data(request: Request): return BaseResponse(code=500, msg=str(e)) +# 监测数据最近7天的数据 +@app.get("/api/xumu/data/past_seven_days") +async def past_seven_days(deviceId): + try: + current_date = datetime.now().date() + past_7_days_date = current_date - timedelta(days=7) + if deviceId is None or deviceId == "" or len(deviceId) != 4: + return BaseResponse(code=500, msg="参数错误") + sql = f"select * from root.farm.{deviceId} where time >= {past_7_days_date} and time <= {current_date}" + send_json = { + "sql": sql + } + r = requests.post(baseHost + queryUri, headers=headers, json=send_json) + return BaseResponse(data=r.json()) + except Exception as e: + return BaseResponse(code=500, msg=str(e)) + + if __name__ == '__main__': uvicorn.run(app, host="0.0.0.0", port=8002)