#!/usr/bin/env python3 """Download the Rejseplanen GTFS feed (all of Denmark) and unzip into data/raw/gtfs/. Source: https://www.rejseplanen.info/labs — a static GTFS zip published by Rejseplanen covering DSB, DSB S-tog, Metroselskabet, Movia, Lokaltog, Hovedstadens Letbane, Skånetrafiken, etc. Nationwide feed; gtfs_to_geopackage.py filters it down to the Copenhagen area. """ import urllib.request import zipfile from _common import GTFS_RAW, UA GTFS_URL = "https://www.rejseplanen.info/labs/GTFS.zip" def main(): GTFS_RAW.mkdir(parents=True, exist_ok=True) zip_path = GTFS_RAW / "feed.zip" print(f"downloading {GTFS_URL} -> {zip_path} ...", flush=True) req = urllib.request.Request(GTFS_URL, headers={"User-Agent": UA}) with urllib.request.urlopen(req) as r, zip_path.open("wb") as f: while chunk := r.read(1 << 20): f.write(chunk) with zipfile.ZipFile(zip_path) as z: z.extractall(GTFS_RAW) zip_path.unlink(missing_ok=True) print(f"extracted GTFS txt files into {GTFS_RAW}") if __name__ == "__main__": main()