Lab 101: Use Open-Meteo API - Authenticate your C...
# pacc-mar-12-13-2024
j
Lab 101: Use Open-Meteo API • Authenticate your CLI to Prefect Cloud • Fine to use a personal account or a workspace • Take a function that fetches data and make it a flow • Use .serve() method to deploy your flow • Run your flow from the UI • Create a schedule for your deployment • Shut down your server • Run a deployment from the CLI, override the params • API docs: open-meteo.com/en/docs • Example: wind speed for the last hour: _weather.json()[“hourly”][“windspeed_10m”][0]_
h
Will something like this do the trick ?
Copy code
import httpx
from prefect import flow

@flow
def fetch_windspeed(lat: float = 39.8, lon: float = -77):
    base_url = "<https://api.open-meteo.com/v1/forecast>"
    speeds = httpx.get(
        base_url,
        params=dict(latitude=lat, longitude=lon, hourly="wind_speed_10m" )
    )
    print("Forecast windspeed:", speeds.json().get('hourly').get('wind_speed_10m')[0])
    return speeds.json().get('hourly').get('wind_speed_10m')[0]
    
if __name__ == "__main__":
    fetch_windspeed.serve(name="lab-101", cron="* * * * *")
🙌 1
sonic 1