yin_home/run.py
尹舟 f5834266e3 Revert "优化代码"
This reverts commit d1591e065b455f94f6ebdd8ba2c4947cad8845d5.
2025-02-11 18:48:50 +08:00

44 lines
954 B
Python

from fastapi import FastAPI
import uvicorn
from utils import query_weather
from utils.log import Log
app = FastAPI()
@app.get('/weather')
def weather():
log = Log().getlog()
response = query_weather.query_weather()
log.info(response)
return response, 200
@app.get('/weather_all')
def weather_all():
log = Log().getlog()
response = query_weather.query_weather(extensions='all')
log.info(response)
return response, 200
@app.get('/weather_flag')
def weather_flag():
log = Log().getlog()
response = query_weather.query_weather()
log.info(response)
weather = response['lives'][0]['weather']
# weather包含雨字符串
if '' in weather:
log.info({"weather": 1})
return {"weather": 1}, 200
else:
log.info({"weather": 0})
return {"weather": 0}, 200
if __name__ == '__main__':
uvicorn.run(app='main:app', host='192.168.31.146', port=1314, reload=True)