INNER CODE UNIT · Python

get_weather_now

datawhalechina/wow-fullstack · tutorial/FastAPI/第6章-FastAPI MCP/main.py:271

async def get_weather_now(
    location: str = Query(..., description="位置ID,如:101010100")
):
    """
    获取指定位置的实时天气
    
    - 需要提供位置ID
    - 返回当前天气详情
    """
    try:
        data = fetch_weather_api("v7/weather/now", {"location": location})
        return data
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

@app.post("/weather/by-city", response_model=WeatherResponse, operation_id="get_weather_by_city", tags=["天气查询"])
async def get_weather_by_city(
    query: WeatherQuery

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…