INNER CODE UNIT · Python
lookup_city
datawhalechina/wow-fullstack · tutorial/FastAPI/第6章-FastAPI MCP/main.py:255
async def lookup_city(
location: str = Query(..., description="城市名称,如:北京")
):
"""
根据城市名称查询位置ID
- 返回城市的详细信息和位置ID
- 位置ID用于后续天气查询
"""
try:
data = fetch_weather_api("geo/v2/city/lookup", {"location": location})
return data
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@app.get("/weather/now", response_model=WeatherResponse, operation_id="get_weather_now", tags=["天气查询"])
async def get_weather_now(
location: str = Query(..., description="位置ID,如:101010100")