Non-official Python wrapper and CLI tool for Trainline
Switch branches/tags
Nothing to show
Clone or download
Latest commit 87e40c8 Sep 16, 2018

README.md

Trainline

Travis Coveralls github PyPI License

Description

Non-official Python wrapper and CLI tool for Trainline

I wrote a French blog post about it here

Requirements

  • Python 3
  • pip3

Installation

pip3 install -U trainline

CLI tool usage

trainline_cli.py --help

Examples :

trainline_cli.py --departure="Toulouse" --arrival="Bordeaux" --next=12hours
trainline_cli.py --departure="Paris" --arrival="Marseille" --next=1day

or the shorter call :

trainline_cli.py -d Toulouse -a Bordeaux -n 12h
trainline_cli.py -d Paris -a Marseille -n 1d

Example output :

departure_date;arrival_date;duration;number_of_segments;price;currency;transportation_mean;bicycle_reservation
15/10/2018 08:19;15/10/2018 10:26;02h07;1;36,0;EUR;train;30,0
15/10/2018 08:19;15/10/2018 10:26;02h07;1;37,5;EUR;train;30,0
15/10/2018 08:19;15/10/2018 10:26;02h07;1;95,5;EUR;train;30,0
[...]

You can then open it with your favorite spreadsheet editor (and play with the filters) :

snapshot trainline_cli.py output in Excel

Package usage

# -*- coding: utf-8 -*-
import trainline

results = trainline.search(
	departure_station="Toulouse",
	arrival_station="Bordeaux",
	from_date="15/10/2018 08:00",
	to_date="15/10/2018 21:00")

print(results.csv())

Example output :

departure_date;arrival_date;duration;number_of_segments;price;currency;transportation_mean;bicycle_reservation
15/10/2018 08:00;15/10/2018 10:55;02h55;1;5,0;EUR;coach;unavailable
15/10/2018 08:00;15/10/2018 10:50;02h50;1;4,99;EUR;coach;unavailable
15/10/2018 08:19;15/10/2018 10:26;02h07;1;20,5;EUR;train;10,0
[...]
# -*- coding: utf-8 -*-
import trainline

Pierre = trainline.Passenger(birthdate="01/01/1980")
Sophie = trainline.Passenger(birthdate="01/02/1981")
Enzo = trainline.Passenger(birthdate="01/03/2012", cards=[trainline.ENFANT_PLUS])

results = trainline.search(
	passengers=[Pierre, Sophie, Enzo],
	departure_station="Toulouse",
	arrival_station="Bordeaux",
	from_date="15/10/2018 08:00",
	to_date="15/10/2018 21:00",
	bicycle_with_or_without_reservation=True)

print(results.csv())

Example output :

departure_date;arrival_date;duration;number_of_segments;price;currency;transportation_mean;bicycle_reservation
15/10/2018 08:19;15/10/2018 10:26;02h07;1;36,0;EUR;train;30,0
15/10/2018 08:19;15/10/2018 10:26;02h07;1;37,5;EUR;train;30,0
15/10/2018 08:19;15/10/2018 10:26;02h07;1;95,5;EUR;train;30,0
[...]

TODO

  • Create a sort function in Folders class (to get the cheapest trips first for example)
  • Add filter for class (first, second), for max_duration
  • Implement get_station_id
  • Implement the use of passengers during search
  • Calculate total price with bicycle reservation if search 'with_bicyle' (and export it in csv)
  • Calculate total price for all the passengers (and export it in csv) => may need to create a class for Folder
  • Create the CLI tool and update README