koleo-izochrona/backend/download_gtfs.py

43 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""
Skrypt do pobierania danych GTFS dla polskich przewoźników kolejowych
"""
import os
import requests
from pathlib import Path
# URL do danych GTFS
GTFS_SOURCES = {
'polish_trains': 'https://mkuran.pl/gtfs/polish_trains.zip',
# Możesz dodać więcej źródeł:
# 'koleje_dolnoslaskie': 'https://kolejedolnoslaskie.pl/...',
}
DATA_DIR = Path(__file__).parent.parent / 'data'
def download_gtfs():
"""Pobiera pliki GTFS z określonych źródeł"""
DATA_DIR.mkdir(exist_ok=True)
for name, url in GTFS_SOURCES.items():
output_file = DATA_DIR / f'{name}.zip'
print(f'Pobieranie {name} z {url}...')
try:
response = requests.get(url, stream=True, timeout=30)
response.raise_for_status()
with open(output_file, 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
print(f'✓ Zapisano do {output_file}')
print(f' Rozmiar: {output_file.stat().st_size / 1024 / 1024:.2f} MB')
except Exception as e:
print(f'✗ Błąd podczas pobierania {name}: {e}')
if __name__ == '__main__':
print('=== Pobieranie danych GTFS ===\n')
download_gtfs()
print('\n=== Zakończono ===')