Spaces:
Runtime error
Runtime error
Download scripts/export_hourly.py from theelvace/weather-data-fetcher-api: direct link, hf CLI and curl.
- Browser
- Download file 902 Bytes
-
https://huggingface.co/spaces/theelvace/weather-data-fetcher-api/resolve/main/scripts/export_hourly.py
- Command line
-
hf download hf://spaces/theelvace/weather-data-fetcher-api/scripts/export_hourly.py
-
curl -L -o export_hourly.py https://huggingface.co/spaces/theelvace/weather-data-fetcher-api/resolve/main/scripts/export_hourly.py
902 Bytes
| import os | |
| import sys | |
| import json | |
| import pandas as pd | |
| os.makedirs("results", exist_ok=True) | |
| with open("data/weather.json") as handle: | |
| data = json.load(handle) | |
| if "hourly" not in data: | |
| print( | |
| "data/weather.json missing 'hourly'. Re-run the fetch step with hourly " | |
| "parameters enabled (see scripts/fetch_weather.sh).", | |
| file=sys.stderr, | |
| ) | |
| sys.exit(1) | |
| H = data["hourly"] | |
| df = pd.DataFrame({ | |
| "time": H["time"], | |
| "temp_c": H["temperature_2m"], | |
| "humidity": H["relative_humidity_2m"], | |
| "cloudcover": H["cloudcover"], | |
| "pressure": H["pressure_msl"], | |
| "wind_speed": H["wind_speed_10m"], | |
| "precip_mm": H["precipitation"], | |
| "rain_mm": H["rain"], | |
| }) | |
| df["time"] = pd.to_datetime(df["time"]) | |
| df = df.sort_values("time").reset_index(drop=True) | |
| df.to_csv("results/hourly.csv", index=False) | |
| print(f"✅ Wrote results/hourly.csv with {len(df)} rows") | |