All Projects → tducret → trainline-python

tducret / trainline-python

Licence: MIT License
Non-official Python wrapper and CLI tool for Trainline

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to trainline-python

locomotive
Python API clients and a CLI for France's railways.
Stars: ✭ 31 (-24.39%)
Mutual labels:  sncf, train
naver news search scraper
검색어 기준으로 네이버뉴스와 댓글을 수집하는 파이썬 코드
Stars: ✭ 38 (-7.32%)
Mutual labels:  scraper
ro.py
ro.py is a modern, asynchronous Python 3 wrapper for the Roblox API.
Stars: ✭ 65 (+58.54%)
Mutual labels:  python-wrapper
ttc subway times
A scraper to grab and publish TTC subway arrival times.
Stars: ✭ 40 (-2.44%)
Mutual labels:  scraper
TorScrapper
A Scraper made 100% in Python using BeautifulSoup and Tor. It can be used to scrape both normal and onion links. Happy Scraping :)
Stars: ✭ 24 (-41.46%)
Mutual labels:  scraper
Stanford-NER-Python
Stanford Named Entity Recognizer (NER) - Python Wrapper
Stars: ✭ 63 (+53.66%)
Mutual labels:  python-wrapper
naver movie scraper
네이버 영화 정보 및 사용자 작성 영화평/평점 데이터 수집기
Stars: ✭ 27 (-34.15%)
Mutual labels:  scraper
railrouter-sg
A progressive web app that lets you explore MRT and LRT rail routes in Singapore
Stars: ✭ 29 (-29.27%)
Mutual labels:  train
scraper
Nodejs web scraper. Contains a command line, docker container, terraform module and ansible roles for distributed cloud scraping. Supported databases: SQLite, MySQL, PostgreSQL. Supported headless clients: Puppeteer, Playwright, Cheerio, JSdom.
Stars: ✭ 37 (-9.76%)
Mutual labels:  scraper
html2rss-web
🕸 Generates and delivers RSS feeds via HTTP. Create your own feeds or get started quickly with the included configs.
Stars: ✭ 36 (-12.2%)
Mutual labels:  scraper
RPICovidScraper
scraper for Rensselaer Polytechnic Institute (RPI)'s Covid Dashboard
Stars: ✭ 12 (-70.73%)
Mutual labels:  scraper
Whatsapp-Group-Contacts-Scraper
How to scrap whatsapp group contacts from https://web.whatsapp.com/
Stars: ✭ 65 (+58.54%)
Mutual labels:  scraper
SocialInfo4J
fetch data from Facebook, Instagram and LinkedIn
Stars: ✭ 44 (+7.32%)
Mutual labels:  scraper
quoters
📝 Random quotes generator package. Available on npm and PyPi
Stars: ✭ 17 (-58.54%)
Mutual labels:  scraper
dijnet-bot
Az összes számlád még egy helyen :)
Stars: ✭ 17 (-58.54%)
Mutual labels:  scraper
mongodb-scraper
Scraps for publicly accessible MongoDB instances and dumps user passwords
Stars: ✭ 33 (-19.51%)
Mutual labels:  scraper
Zeiver
A Scraper, Downloader, & Recorder for static open directories.
Stars: ✭ 14 (-65.85%)
Mutual labels:  scraper
dolarPy
Checks USD/PYG exchange rate from several sites, with a calculator, RESTful API and a twitter bot
Stars: ✭ 45 (+9.76%)
Mutual labels:  scraper
ttv
A command line tool for splitting files into test, train, and validation sets.
Stars: ✭ 38 (-7.32%)
Mutual labels:  train
bots-zoo
No description or website provided.
Stars: ✭ 59 (+43.9%)
Mutual labels:  scraper

Trainline

Travis Coveralls github PyPI Docker Image size License

Description

Non-official Python wrapper and CLI tool for Trainline

I wrote a French blog post about it here

🎁 I added a tiny Docker image to use the tool very easily

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", cards=[trainline.AVANTAGE_FAMILLE])
Sophie = trainline.Passenger(birthdate="01/02/1981")
Enzo = trainline.Passenger(birthdate="01/03/2012")
Nicolas = trainline.Passenger(birthdate="01/01/1996", cards=[trainline.AVANTAGE_JEUNE])
Nicolas.add_special_card(trainline.TGVMAX, "YourCardNumber")

results = trainline.search(
	passengers=[Pierre, Sophie, Enzo, Nicolas],
	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
[...]

Docker

You can use the trainline tool with the Docker image

You may execute :

docker run -it --rm thibdct/trainline --departure="Toulouse" --arrival="Bordeaux" --next=12hours

The Docker image is built on top of Google Distroless image, so it is tiny :)

🤘 The easy way 🤘

I also built a bash wrapper to execute the Docker container easily.

Install it with :

curl -s https://raw.githubusercontent.com/tducret/trainline-python/master/trainline.sh \
> /usr/local/bin/trainline && chmod +x /usr/local/bin/trainline

You may replace /usr/local/bin with another folder that is in your $PATH

Check that it works :

trainline --help
trainline --departure="Toulouse" --arrival="Bordeaux" --next=12hours

You can upgrade the app with :

trainline --upgrade

and even uninstall with :

trainline --uninstall

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].