aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--.task/checksum/build-osm1
m---------build_renfe0
-rw-r--r--vitrasa_extend/extend.py69
4 files changed, 72 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 3ebf6bc..d375aec 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
+# Taskfile
+.task/
+
# Blobs
*.osm.pbf
*.obj
diff --git a/.task/checksum/build-osm b/.task/checksum/build-osm
deleted file mode 100644
index 73c6074..0000000
--- a/.task/checksum/build-osm
+++ /dev/null
@@ -1 +0,0 @@
-c2fe2e957c8f45b635152704dcfad2c4
diff --git a/build_renfe b/build_renfe
-Subproject dd582884a7d355513739df5828022b75780a0da
+Subproject e2c56e662c196d74bd5b33453cfdfc81488fdc5
diff --git a/vitrasa_extend/extend.py b/vitrasa_extend/extend.py
new file mode 100644
index 0000000..458e306
--- /dev/null
+++ b/vitrasa_extend/extend.py
@@ -0,0 +1,69 @@
+# /// script
+# requires-python = ">=3.12"
+# dependencies = [
+# "requests"
+# ]
+# ///
+
+from argparse import ArgumentParser
+import csv
+import json
+import logging
+import os
+import shutil
+import tempfile
+import zipfile
+
+
+def get_rows(input_file: str) -> list[dict]:
+ rows: list[dict] = []
+
+ with open(input_file, "r", encoding="utf-8") as f:
+ reader = csv.DictReader(f)
+ if reader.fieldnames is None:
+ return []
+ reader.fieldnames = [name.strip() for name in reader.fieldnames]
+
+ for row in reader:
+ rows.append(row)
+
+ return rows
+
+
+if __name__ == "__main__":
+ parser = ArgumentParser()
+ parser.add_argument(
+ "--debug",
+ help="Enable debug logging",
+ action="store_true"
+ )
+
+ args = parser.parse_args()
+
+ logging.basicConfig(
+ level=logging.DEBUG if args.debug else logging.INFO,
+ format="%(asctime)s - %(levelname)s - %(message)s",
+ )
+
+ GTFS_TEMPWORKDIR = tempfile.mkdtemp(prefix="vitrasa_extend_")
+
+ # Unzip the GTFS feed
+ with zipfile.ZipFile("../feeds/vitrasa.zip", "r") as zip_ref:
+ zip_ref.extractall(GTFS_TEMPWORKDIR)
+
+ CALENDAR_DATES_FILE = os.path.join(GTFS_TEMPWORKDIR, "calendar_dates.txt")
+ # Open the calendar_dates.txt file, and copy
+
+ # Create a ZIP archive of the output GTFS
+ with zipfile.ZipFile("../feeds/vitrasa_fixed.zip", "w", zipfile.ZIP_DEFLATED) as zipf:
+ for root, _, files in os.walk(GTFS_TEMPWORKDIR):
+ for file in files:
+ file_path = os.path.join(root, file)
+ arcname = os.path.relpath(file_path, GTFS_TEMPWORKDIR)
+ zipf.write(file_path, arcname)
+
+ logging.info(
+ "GTFS data from feed has been zipped successfully at ../feeds/vitrasa_fixed.zip."
+ )
+
+ shutil.rmtree(GTFS_TEMPWORKDIR)