past_seven_days

This commit is contained in:
xyj 2024-02-20 10:43:04 +08:00
parent 154e539d13
commit ebc89ca249
1 changed files with 19 additions and 2 deletions

21
xumu.py
View File

@ -1,8 +1,7 @@
import re import re
import time
import json import json
from typing import Any from typing import Any
from datetime import datetime, timedelta
import requests import requests
import uvicorn import uvicorn
from fastapi import FastAPI, Request from fastapi import FastAPI, Request
@ -327,5 +326,23 @@ async def process_data(request: Request):
return BaseResponse(code=500, msg=str(e)) 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__': if __name__ == '__main__':
uvicorn.run(app, host="0.0.0.0", port=8002) uvicorn.run(app, host="0.0.0.0", port=8002)