From ebc89ca2498784d3b62e03343b934b657f8f1599 Mon Sep 17 00:00:00 2001 From: xyj <10908227994@qq.com> Date: Tue, 20 Feb 2024 10:43:04 +0800 Subject: [PATCH] past_seven_days --- xumu.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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)