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='0.0.0.0', port=1314, reload=True)