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 -21
View File
@@ -10,12 +10,8 @@ managed by the government of Asturias/León:
Primary source: infonieve.es (https://www.infonieve.es/estacion-esqui/{slug}/)
Fallback: returns None values with a logged warning when scraping fails.
Raw responses are saved to:
data/raw/station_{station_id}_{date}.json
"""
import json
import logging
import re
from datetime import date
@@ -34,8 +30,6 @@ logger = logging.getLogger(__name__)
_PROJECT_ROOT = Path(__file__).resolve().parent.parent
_CONFIG_PATH = _PROJECT_ROOT / "config" / "stations.yaml"
_RAW_DATA_DIR = _PROJECT_ROOT / "data" / "raw"
_USER_AGENT = (
"Mozilla/5.0 (X11; Linux x86_64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
@@ -94,19 +88,6 @@ def _get_session() -> requests.Session:
return session
def _save_raw(station_id: str, payload: dict) -> None:
"""Persist raw scraped payload to data/raw/ as JSON."""
_RAW_DATA_DIR.mkdir(parents=True, exist_ok=True)
today = date.today().isoformat()
filename = _RAW_DATA_DIR / f"station_{station_id}_{today}.json"
try:
with open(filename, "w", encoding="utf-8") as fh:
json.dump(payload, fh, ensure_ascii=False, indent=2)
logger.debug("Raw data saved to %s", filename)
except OSError as exc:
logger.warning("Could not save raw data for %s: %s", station_id, exc)
def _parse_float(text: Optional[str]) -> Optional[float]:
"""Extract the first float-like value from a string, or return None."""
if not text:
@@ -305,7 +286,6 @@ class StationScraper:
logger.info("Scraping station: %s", station_id)
record = self._scrape_infonieve(station_id)
_save_raw(station_id, record)
return record
def scrape_all_stations(self) -> list[dict]:
@@ -402,4 +382,4 @@ if __name__ == "__main__":
)
scraper = StationScraper()
records = scraper.scrape_all_stations()
print(json.dumps(records, indent=2, ensure_ascii=False))
print(records)