123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- from fastapi import APIRouter, Request, Depends, Query, HTTPException, status
- from common.security import valid_access_token
- from sqlalchemy.orm import Session
- from sqlalchemy.sql import func
- from common.auth_user import *
- from sqlalchemy import text
- from pydantic import BaseModel
- from common.BigDataCenterAPI import *
- from database import get_db
- from typing import List
- from utils import *
- from utils.risk import *
- import json
- import traceback
- from datetime import datetime, timedelta
- router = APIRouter()
- @router.post('/temperature')
- async def mine(request: Request,db: Session = Depends(get_db)):
- try:
- body = await request.json()
- args = body.get("args")
- print(args)
- result = []
- if args == "6h_precipitation":
- result.append(
- {"create_time":"",
- "pic_url":"https://soc.gd121.cn/sk6hrain/2024/10/MSP1_AGD_MANOBS_PRCPV_L88_AGD_202410071400_00600-00000.PNG"
- }
- )
- result.append(
- {"create_time": "",
- "pic_url": "https://soc.gd121.cn/sk6hrain/2024/10/MSP1_AGD_MANOBS_PRCPV_L88_AGD_202410071500_00600-00000.PNG"
- }
- )
- result.append(
- {"create_time": "",
- "pic_url": "https://soc.gd121.cn/sk6hrain/2024/10/MSP1_AGD_MANOBS_PRCPV_L88_AGD_202410071600_00600-00000.PNG"
- }
- )
- elif args == "24h_precipitation":
- result.append(
- {"create_time": "",
- "pic_url": "https://soc.gd121.cn/sk24hrain/2024/10/MSP1_AGD_MANOBS_PRCPV_L88_AGD_202410071400_02400-00000.PNG"}
- )
- result.append(
- {"create_time": "",
- "pic_url": "https://soc.gd121.cn/sk24hrain/2024/10/MSP1_AGD_MANOBS_PRCPV_L88_AGD_202410071500_02400-00000.PNG"}
- )
- result.append(
- {"create_time": "",
- "pic_url": "https://soc.gd121.cn/sk24hrain/2024/10/MSP1_AGD_MANOBS_PRCPV_L88_AGD_202410071600_02400-00000.PNG"}
- )
- elif args == "hourly_temperature":
- result.append(
- {"create_time": "",
- "pic_url": "https://soc.gd121.cn/skt/2024/10/MSP1_AGD_MANOBS_T_L88_AGD_202410071300_00000-00000.PNG"}
- )
- result.append(
- {"create_time": "",
- "pic_url": "https://soc.gd121.cn/skt/2024/10/MSP1_AGD_MANOBS_T_L88_AGD_202410071400_00000-00000.PNG"}
- )
- result.append(
- {"create_time": "",
- "pic_url": "https://soc.gd121.cn/skt/2024/10/MSP1_AGD_MANOBS_T_L88_AGD_202410071500_00000-00000.PNG"}
- )
- elif args == "24h_max_temperature":
- result.append(
- {"create_time": "",
- "pic_url": "https://soc.gd121.cn/sk24htmax/2024/10/MSP1_AGD_MANOBS_TMA_L88_AGD_202410071300_02400-00000.PNG"
- }
- )
- result.append(
- {"create_time": "",
- "pic_url": "https://soc.gd121.cn/sk24htmax/2024/10/MSP1_AGD_MANOBS_TMA_L88_AGD_202410071400_02400-00000.PNG"
- }
- )
- result.append(
- {"create_time": "",
- "pic_url": "https://soc.gd121.cn/sk24htmax/2024/10/MSP1_AGD_MANOBS_TMA_L88_AGD_202410071500_02400-00000.PNG"
- }
- )
- elif args == "24h_min_temperature":
- result.append(
- {"create_time": "",
- "pic_url": "https://soc.gd121.cn/sk24htmin/2024/10/MSP1_AGD_MANOBS_TMI_L88_AGD_202410071300_02400-00000.PNG"}
- )
- result.append(
- {"create_time": "",
- "pic_url": "https://soc.gd121.cn/sk24htmin/2024/10/MSP1_AGD_MANOBS_TMI_L88_AGD_202410071400_02400-00000.PNG"}
- )
- result.append(
- {"create_time": "",
- "pic_url": "https://soc.gd121.cn/sk24htmin/2024/10/MSP1_AGD_MANOBS_TMI_L88_AGD_202410071500_02400-00000.PNG"}
- )
- elif args == "24h_variable_temperature":
- result.append(
- {"create_time": "",
- "pic_url": "https://soc.gd121.cn/skimg/dt/BA3F7CC721A162A2149136AFE95CD8FE/A754169EFBBB6FA567B77735CED069F4.png"}
- )
- result.append(
- {"create_time": "",
- "pic_url": "https://soc.gd121.cn/skimg/dt/BA3F7CC721A162A2149136AFE95CD8FE/8A4271D80721F5497CEA242D0BD775BB.png"}
- )
- result.append(
- {"create_time": "",
- "pic_url": "https://soc.gd121.cn/skimg/dt/BA3F7CC721A162A2149136AFE95CD8FE/368D21EBBEA399BC2A119D0E54316C48.png"}
- )
- print(result)
- return {
- "code": 200,
- "msg": "成功",
- "data":
- {"max_level":result}
- }
- except Exception as e:
- db.rollback()
- traceback.print_exc()
- raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
- def make_url(dt):
- base_url = "https://soc.gd121.cn/cappi/{年}/{月}/CAPPI_440000_{年月日时}0000.png!wbdstyle"
- # 格式化日期和时间
- year = dt.strftime("%Y")
- month = dt.strftime("%m")
- day = dt.strftime("%d")
- hour = dt.strftime("%H")
- # 构造完整的URL
- url = base_url.format(年=year, 月=month, 年月日时=f"{year}{month}{day}{hour}")
- return url
- @router.get('/radar_chart')
- @router.post('/radar_chart')
- async def mine(request: Request,db: Session = Depends(get_db)):
- try:
- now = datetime.now()-timedelta(hours=1)
- urls = []
- for i in range(12):
- dt = now - timedelta(hours=i)
- if dt.hour == 0 and i > 0:
- dt -= timedelta(days=1)
- print(dt)
- urls.append(
- {
- "time":dt.strftime("%Y-%m-%d %H:00:00"),
- "url":make_url(dt)
- }
- )
- urls = urls[::-1]
- return {
- "code": 200,
- "msg": "成功",
- "data":
- urls
- }
- except Exception as e:
- db.rollback()
- traceback.print_exc()
- raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|