feat(storage): migrate project to sqlite

This commit is contained in:
dasemu committed 2026-03-13 06:50:18 +01:00
1 parent 1bc1e58781
commit 9c8ba03574
17 files changed
+1204 -688

No files matched your search

+1 -26
View File
@@ -1,7 +1,7 @@
"""Weather data collector using Open-Meteo API.
Fetches historical and forecast weather data for ski stations
defined in config/stations.yaml. No API key required.
defined in config/stations.yaml and persists snapshots in SQLite.
Historical endpoint: https://archive-api.open-meteo.com/v1/archive
Forecast endpoint: https://api.open-meteo.com/v1/forecast
@@ -24,8 +24,6 @@ logger = logging.getLogger(__name__)
BASE_DIR = Path(__file__).resolve().parent.parent
CONFIG_PATH = BASE_DIR / "config" / "stations.yaml"
RAW_DATA_DIR = BASE_DIR / "data" / "raw"
HISTORICAL_URL = "https://archive-api.open-meteo.com/v1/archive"
FORECAST_URL = "https://api.open-meteo.com/v1/forecast"
@@ -65,7 +63,6 @@ class WeatherCollector:
def __init__(self, config_path: Path = CONFIG_PATH) -> None:
self.config_path = config_path
self.stations = self._load_stations()
RAW_DATA_DIR.mkdir(parents=True, exist_ok=True)
# ------------------------------------------------------------------
# Public API
@@ -126,8 +123,6 @@ class WeatherCollector:
raw = self._request(HISTORICAL_URL, params)
df = self._parse_response(raw, station_id)
self._save(df, station_id)
return df
def get_forecast(
@@ -169,8 +164,6 @@ class WeatherCollector:
raw = self._request(FORECAST_URL, params)
df = self._parse_response(raw, station_id)
self._save(df, station_id)
return df
def collect_all_stations(
@@ -338,21 +331,3 @@ class WeatherCollector:
# Keep only the expected column order
columns = ["date"] + DAILY_VARIABLES + ["station_id"]
return df[columns]
def _save(self, df: pd.DataFrame, station_id: str) -> None:
"""Persist a weather DataFrame to a CSV file.
Filename format: ``weather_{station_id}_{date}.csv``
where ``{date}`` is today's date (the collection date).
Parameters
----------
df:
DataFrame to save.
station_id:
Station identifier used in the filename.
"""
today = date.today().strftime("%Y-%m-%d")
filename = RAW_DATA_DIR / f"weather_{station_id}_{today}.csv"
df.to_csv(filename, index=False)
logger.info("Saved weather data to %s", filename)