yin_home/run.py

44 lines
954 B
Python
Raw Normal View History

2025-02-11 17:27:11 +08:00
from fastapi import FastAPI
import uvicorn
2025-02-11 16:04:10 +08:00
from utils import query_weather
from utils.log import Log
app = FastAPI()
2025-02-11 16:04:10 +08:00
@app.get('/weather')
2025-02-11 16:04:10 +08:00
def weather():
log = Log().getlog()
2025-02-11 16:04:10 +08:00
response = query_weather.query_weather()
log.info(response)
return response, 200
2025-02-11 16:04:10 +08:00
@app.get('/weather_all')
2025-02-11 16:04:10 +08:00
def weather_all():
log = Log().getlog()
2025-02-11 16:04:10 +08:00
response = query_weather.query_weather(extensions='all')
log.info(response)
return response, 200
2025-02-11 16:04:10 +08:00
@app.get('/weather_flag')
2025-02-11 16:04:10 +08:00
def weather_flag():
log = Log().getlog()
response = query_weather.query_weather()
log.info(response)
2025-02-11 16:04:10 +08:00
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
2025-02-11 16:04:10 +08:00
if __name__ == '__main__':
2025-02-11 18:13:27 +08:00
uvicorn.run(app='main:app', host='192.168.31.146', port=1314, reload=True)