Skip to main content

Train traveler is a backend for SNCF API

Project description

Train Traveler

Warning

Train Traveler is currently under construction and is in alpha stage. Use at your own risk. Features and functionality may change.

Train Traveler is a versatile tool for accessing SNCF train information. It provides both a Python module offering a framework to access the SNCF API and an interactive command-line interface (CLI) to retrieve upcoming trains for a specified departure and destination, as well as the last journey of the day.

Table of Contents

Features

  • SNCF API Access Framework: Easily interact with the SNCF API to retrieve train information.
  • Interactive Command-Line Interface: Quickly get upcoming trains and the last journey of the day via CLI.
  • Custom Searches: Specify departure and arrival stations to get precise information.
  • Journey History: Check the last journeys of the day.

Installation

  1. Clone the GitHub repository:

    git clone https://github.com/Matthyeux/train-traveler-api.git
    
  2. Navigate to the project directory:

    cd train-traveler-api
    

Usage

As a Python Module

You can use Train Traveler as a Python module to interact with the SNCF API in your own scripts.

from sncf.connections.connection_manager import ApiConnectionManager

from sncf.repositories.journey_repository import ApiJourneyRepository 
from sncf.repositories.stop_area_repository import ApiStopAreaRepository
from sncf.repositories.disruption_repository import ApiDisruptionRepository

from sncf.services.journey_service import JourneyService


# Initialize the client with your API key
# url = https://api.sncf.com/v1
# api_key = your api key
# region = sncf
connection = ApiConnectionManager(url, api_key, region)

# Initiatlize journey_service
journey_service = JourneyService(
    stop_area_repository=ApiStopAreaRepository(connection),
    journey_repository=ApiJourneyRepository(connection),
    disruption_repository=ApiDisruptionRepository(connection)
)

departure = Area('stop_area:SNCF:87391003', 'Paris - Montparnasse - Hall 1 & 2 (Paris)', 'Paris - Montparnasse - Hall 1 & 2', {'lon': '2.320514', 'lat': '48.841172'})

destination = Area('stop_area:SNCF:87581009', 'Bordeaux Saint-Jean (Bordeaux)', 'Bordeaux Saint-Jean', {'lon': '-0.556697', 'lat': '44.825873'})

# Get the next trains
# Count is the number of journeys to retrieve
next_trains = journey_service.get_direct_journeys(departure, destination, count=2)

# Get the last train of the day
last_train = journey_service.get_last_direct_journeys(departure, destination)

As a Command-Line Tool

Train Traveler includes a CLI for quick and interactive use.

# Get the next trains
train-traveler journey --from Paris --to Bordeaux --max-journeys 2

# Get the last train of the day
train-traveler journey --from Paris --to Bordeaux --last-journey

Configuration

To use the SNCF API, you need to obtain an API key from the SNCF Developer Portal.

Set your API key by defining the url, region and api_key, in config/auth.yml or by setting:

export SNCF_API_URL='https://api.sncf.com/v1'
export SNCF_API_REGION='sncf'
export SNCF_API_KEY='your_api_key'

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss the changes you want to make.

Fork the project
Create your feature branch (git checkout -b feature/AmazingFeature)
Commit your changes (git commit -m 'Add some AmazingFeature')
Push to the branch (git push origin feature/AmazingFeature)
Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

train_traveler_api-0.1.0a1716563972.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

train_traveler_api-0.1.0a1716563972-py3-none-any.whl (22.8 kB view details)

Uploaded Python 3

File details

Details for the file train_traveler_api-0.1.0a1716563972.tar.gz.

File metadata

File hashes

Hashes for train_traveler_api-0.1.0a1716563972.tar.gz
Algorithm Hash digest
SHA256 9c233191169e35c78247d0ba9e79fabf58078b99b4d6c1f26b9a873c1462856c
MD5 afa2e3f9adff231403c12f9ffd1e3f47
BLAKE2b-256 4f711e0ce1cf0272492185c500b37698143d14a831d854c90d81e3a2b1242b4a

See more details on using hashes here.

File details

Details for the file train_traveler_api-0.1.0a1716563972-py3-none-any.whl.

File metadata

File hashes

Hashes for train_traveler_api-0.1.0a1716563972-py3-none-any.whl
Algorithm Hash digest
SHA256 410c2709c15c0caa0a3f94786c29196a1cd6eae167087245310e9bc98c9569a7
MD5 11f422bc2e206e3a2becb090b0a349e6
BLAKE2b-256 f397097cbedfbcac5e9f964ceae27f6951e302b4d7087af7db582ae58c4c3b5b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page