Skip to content

Instantly share code, notes, and snippets.

@discdiver
Created September 20, 2023 15:28
Show Gist options
  • Save discdiver/93999e38db5249d7dc718e90134b18ab to your computer and use it in GitHub Desktop.
Save discdiver/93999e38db5249d7dc718e90134b18ab to your computer and use it in GitHub Desktop.
Prefect serve method code from demo video
import requests
from prefect import flow
@flow(log_prints=True)
def fetch_weather(lat: float = 38.9, lon: float = -77.0):
weather = requests.get(
"https://api.open-meteo.com/v1/forecast/",
params=dict(latitude=lat, longitude=lon, hourly="temperature_2m"),
)
most_recent_temp = float(weather.json()["hourly"]["temperature_2m"][0])
print(f"Most recent temp C: {most_recent_temp} degrees")
return
if __name__ == "__main__":
fetch_weather.serve(name="get-weather", cron="0 0 * * *")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment