aboutsummaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
Diffstat (limited to 'data')
-rw-r--r--data/download-stops.py117
-rw-r--r--data/stop-overrides.yaml38
2 files changed, 155 insertions, 0 deletions
diff --git a/data/download-stops.py b/data/download-stops.py
new file mode 100644
index 0000000..2720014
--- /dev/null
+++ b/data/download-stops.py
@@ -0,0 +1,117 @@
+#!/usr/bin/env python3
+import json
+import os
+import sys
+import urllib.request
+import yaml # Add YAML support for overrides
+
+def load_stop_overrides(file_path):
+ """Load stop overrides from a YAML file"""
+ if not os.path.exists(file_path):
+ print(f"Warning: Overrides file {file_path} not found")
+ return {}
+
+ try:
+ with open(file_path, 'r', encoding='utf-8') as f:
+ overrides = yaml.safe_load(f)
+ print(f"Loaded {len(overrides) if overrides else 0} stop overrides")
+ return overrides or {}
+ except Exception as e:
+ print(f"Error loading overrides: {e}", file=sys.stderr)
+ return {}
+
+def apply_overrides(stops, overrides):
+ """Apply overrides to the stop data"""
+ for stop in stops:
+ stop_id = stop.get("stopId")
+ if stop_id in overrides:
+ override = overrides[stop_id]
+
+ # Apply name override
+ if "name" in override:
+ stop["name"] = override["name"]
+
+ # Apply or add alternate names
+ if "alternateNames" in override:
+ if isinstance(stop["name"], str):
+ # Convert simple name to object if it's a string
+ original_name = stop["name"]
+ stop["name"] = {"original": original_name}
+
+ # Add alternate names
+ for key, value in override["alternateNames"].items():
+ stop["name"][key] = value
+
+ # Apply location override
+ if "location" in override:
+ if "latitude" in override["location"]:
+ stop["latitude"] = override["location"]["latitude"]
+ if "longitude" in override["location"]:
+ stop["longitude"] = override["location"]["longitude"]
+
+ # Add notes
+ if "notes" in override:
+ stop["notes"] = override["notes"]
+
+ # Add active status
+ if "active" in override:
+ stop["active"] = override["active"]
+
+ # Add amenities
+ if "amenities" in override:
+ stop["amenities"] = override["amenities"]
+
+ print(f"Applied overrides to stop {stop_id} ({stop['name']})")
+
+ return stops
+
+def main():
+ print("Fetching stop list data...")
+
+ # Download stop list data
+ url = "https://datos.vigo.org/vci_api_app/api2.jsp?tipo=TRANSPORTE_PARADAS"
+ req = urllib.request.Request(url)
+
+ try:
+ with urllib.request.urlopen(req) as response:
+ # Read the response and decode from ISO-8859-1 to UTF-8
+ content = response.read().decode('iso-8859-1')
+ data = json.loads(content)
+
+ print(f"Downloaded {len(data)} stops")
+
+ # Process the data
+ processed_stops = []
+ for stop in data:
+ processed_stop = {
+ "stopId": stop.get("id"),
+ "name": {
+ "original": stop.get("nombre", "")
+ },
+ "latitude": stop.get("lat"),
+ "longitude": stop.get("lon"),
+ "lines": [line.strip() for line in stop.get("lineas", "").split(",")] if stop.get("lineas") else []
+ }
+ processed_stops.append(processed_stop)
+
+ # Load and apply overrides
+ script_dir = os.path.dirname(os.path.abspath(__file__))
+ overrides_file = os.path.join(script_dir, "stop-overrides.yaml")
+ overrides = load_stop_overrides(overrides_file)
+ processed_stops = apply_overrides(processed_stops, overrides)
+
+ # Save to public directory
+ output_file = os.path.join(script_dir, "..", "public", "stops.json")
+
+ with open(output_file, 'w', encoding='utf-8') as f:
+ json.dump(processed_stops, f, ensure_ascii=False, indent=2)
+
+ print(f"Saved processed stops data to {output_file}")
+ return 0
+
+ except Exception as e:
+ print(f"Error processing stops data: {e}", file=sys.stderr)
+ return 1
+
+if __name__ == "__main__":
+ sys.exit(main()) \ No newline at end of file
diff --git a/data/stop-overrides.yaml b/data/stop-overrides.yaml
new file mode 100644
index 0000000..6dfc23f
--- /dev/null
+++ b/data/stop-overrides.yaml
@@ -0,0 +1,38 @@
+# This file contains overrides for specific bus stops.
+# Format:
+# stopId: # Numeric ID of the stop to override
+# name: # Override the name
+# alternateNames: # Additional names for the stop
+# metro: # Stop name in
+# location: # Override location coordinates
+# latitude: # New latitude value
+# longitude: # New longitude value
+# notes: # Additional notes about the stop
+# active: # Boolean to indicate if stop is active
+# amenities: # List of amenities available at this stop
+# - shelter # Marquesina
+# - real-time display # Display with real-time information
+
+6930: # Praza de América 1
+ alternateNames:
+ intersect: "Praza América - Camelias"
+ amenities:
+ - shelter
+ - real-time display
+
+14264:
+ alternateNames:
+ intersect: "Urzáiz - Príncipe"
+ amenities:
+ - shelter
+ - real-time display
+
+6620:
+ location:
+ latitude: 42.23757846151978
+ longitude: -8.721031378896738
+
+20193:
+ location:
+ latitude: 42.23767601188501
+ longitude: -8.721582630122455 \ No newline at end of file