Spaces:
Sleeping
Sleeping
|
Download DOC.md from DavidRambeau/happytrain_back: direct link, hf CLI and curl.
- Browser
- Download file 2.73 kB
-
https://huggingface.co/spaces/DavidRambeau/happytrain_back/resolve/main/DOC.md
- Command line
-
hf download hf://spaces/DavidRambeau/happytrain_back/DOC.md
-
curl -L -o DOC.md https://huggingface.co/spaces/DavidRambeau/happytrain_back/resolve/main/DOC.md
2.73 kB
| # API Horaires SNCF — GTFS | |
| API REST FastAPI pour consulter les horaires des prochains trains depuis les données GTFS SNCF. | |
| ## Installation | |
| ```bash | |
| pip install fastapi uvicorn pandas | |
| ``` | |
| ## Démarrage rapide | |
| ### 1. Construire la base SQLite | |
| ```bash | |
| # Placer les fichiers GTFS dans ./uploads/ | |
| python build_db.py --uploads-dir ./uploads --db gtfs_sncf.db | |
| ``` | |
| ### 2. Lancer l'API | |
| ```bash | |
| uvicorn main:app --reload | |
| # → http://localhost:8013 | |
| # → http://localhost:8013/docs (Swagger UI interactif) | |
| ``` | |
| ### Variable d'environnement | |
| ```bash | |
| export DB_PATH=/chemin/vers/gtfs_sncf.db | |
| uvicorn main:app --reload | |
| ``` | |
| --- | |
| ## Endpoints | |
| | Méthode | URL | Description | | |
| |---------|-----|-------------| | |
| | GET | `/` | Index des endpoints | | |
| | GET | `/health` | Statut + stats tables | | |
| | GET | `/stops/search?q=Paris` | Chercher une gare | | |
| | GET | `/stops/{stop_id}` | Détails d'un arrêt | | |
| | GET | `/next-trains?stop_id=...` | Prochains trains depuis une gare | | |
| | GET | `/trains?from_stop_id=...&to_stop_id=...` | Trains directs entre 2 gares | | |
| | GET | `/routes?q=TGV` | Rechercher une ligne | | |
| | GET | `/routes/{route_id}/stops` | Arrêts d'une ligne | | |
| --- | |
| ## Exemple d'utilisation | |
| ```bash | |
| # 1. Trouver l'identifiant de Lyon Part Dieu | |
| curl "http://localhost:8013/stops/search?q=Lyon+Part+Dieu" | |
| # → stop_id: "StopPoint:OCETrain TER-87723197" | |
| # 2. Prochains trains aujourd'hui à partir de maintenant | |
| curl "http://localhost:8013/next-trains?stop_id=StopPoint:OCETrain%20TER-87723197" | |
| # 3. Trains directs Lyon → Paris demain matin | |
| curl "http://localhost:8013/trains?from_stop_id=StopPoint:OCETGV%20INOUI-87723197&to_stop_id=StopPoint:OCETGV%20INOUI-87113001&date=20260219&time=07:00:00" | |
| ``` | |
| --- | |
| ## Structure des fichiers GTFS attendus | |
| ``` | |
| uploads/ | |
| ├── agency.txt — Opérateurs (SNCF Voyageurs…) | |
| ├── routes.csv — Lignes | |
| ├── trips.txt — Trajets / courses | |
| ├── stop_times2.csv — Horaires arrêt par arrêt (sep=;) | |
| ├── stops.csv — Points d'arrêt | |
| ├── calendar_dates.txt — Dates de circulation | |
| ├── transfers.txt — Correspondances | |
| └── feed_info.txt — Métadonnées du flux | |
| ``` | |
| --- | |
| ## Notes techniques | |
| - Les `stop_id` SNCF contiennent le type de train : `StopPoint:OCETrain TER-87723197`, `StopPoint:OCETGV INOUI-87723197`, etc. Un même arrêt physique peut avoir plusieurs `stop_id` selon le type de train. | |
| - Le champ `departure_time` peut dépasser `24:00:00` (ex : `25:30:00`) pour les trains de nuit — c'est du GTFS standard. | |
| - La table `calendar_dates` gère uniquement les exceptions (exception_type=1 = service actif, 2 = supprimé). | |
| ## Requirements | |
| ``` | |
| fastapi>=0.110 | |
| uvicorn>=0.29 | |
| pandas>=2.0 | |
| ``` | |