优化代码
This commit is contained in:
		
							parent
							
								
									36b33e782c
								
							
						
					
					
						commit
						d1591e065b
					
				@ -17,4 +17,4 @@ RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua
 | 
			
		||||
COPY . .
 | 
			
		||||
 | 
			
		||||
# 运行应用程序
 | 
			
		||||
ENTRYPOINT ["python3", "run.py"]
 | 
			
		||||
ENTRYPOINT ["python3", "main.py"]
 | 
			
		||||
@ -3,40 +3,28 @@ import uvicorn
 | 
			
		||||
from utils import query_weather
 | 
			
		||||
from utils.log import Log
 | 
			
		||||
 | 
			
		||||
app = FastAPI()
 | 
			
		||||
app = FastAPI(title="yin_home文档")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.get('/weather')
 | 
			
		||||
@app.get('/weather', tags=["获取天气数据"], summary="返回实时天气数据")
 | 
			
		||||
def weather():
 | 
			
		||||
    log = Log().getlog()
 | 
			
		||||
    response = query_weather.query_weather()
 | 
			
		||||
    log.info(response)
 | 
			
		||||
 | 
			
		||||
    return response, 200
 | 
			
		||||
    return response
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.get('/weather_all')
 | 
			
		||||
@app.get('/weather_all', tags=["获取天气数据"], summary="返回天气预报数据")
 | 
			
		||||
def weather_all():
 | 
			
		||||
    log = Log().getlog()
 | 
			
		||||
    response = query_weather.query_weather(extensions='all')
 | 
			
		||||
    log.info(response)
 | 
			
		||||
 | 
			
		||||
    return response, 200
 | 
			
		||||
    return response
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.get('/weather_flag')
 | 
			
		||||
@app.get('/weather_flag', tags=["获取天气数据"], summary="返回实时天气数据状态码")
 | 
			
		||||
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
 | 
			
		||||
    log.info(weather)
 | 
			
		||||
    return 1 if '雨' in weather else 0
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
@ -1,12 +1,14 @@
 | 
			
		||||
import requests
 | 
			
		||||
from utils.log import Log
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def query_weather(key="3add99f10c5144ebd64bfa0bfb6b1c20", city="420115", extensions="base", output="JSON"):
 | 
			
		||||
    log = Log().getlog()
 | 
			
		||||
    url = "https://restapi.amap.com/v3/weather/weatherInfo"
 | 
			
		||||
 | 
			
		||||
    querystring = {"key": key, "city": city, "extensions": extensions,
 | 
			
		||||
                   "output": output}
 | 
			
		||||
 | 
			
		||||
    response = requests.request("GET", url, params=querystring)
 | 
			
		||||
 | 
			
		||||
    log.info(response.json())
 | 
			
		||||
    return response.json()
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user