Get faster Renfe Spanish Trains timetables in your terminal.
Project description
Renfe Timetables CLI
Get faster Renfe trains timetables in your terminal, with Python3.7+ support. No longer need to open the browser! Just keep using your terminal 😀
It supports both Horarios de alta velocidad, larga distancia y media distancia (default option, as in the web) and Renfe Cercanías GTFS datasets.
renfe-cli
is written in Rust (since v4.0.0) and published to pypi.org as a Python package (CLI and library).
See the changelog.
NOTE since I am more often using Rodalies trains I have created rodalies-cli. I hope you like it too!
DISCLAIMER: Renfe's GTFS dataset might not be in sync with autonomic train schedules systems (e.g. Rodalies de la Generalitat de Catalunya), hence Renfe Cercanias train types (e.g.: REGIONAL or MD type) might not be accurate, or when using the cercanias
flag you won't find timetables for the stations belonging to autonomic systems. For that, please use autonomic data/apps (.e.g: rodalies-cli).
Installation
Install Python CLI package renfe-cli
pip install renfe-cli --upgrade
Usage (CLI)
The CLI uses the official and latest Renfe's GTFS dataset, from Horarios de alta velocidad, larga distancia y media distancia, by default. Optionally, one can enable searching over Renfe Cercanías GTFS dataset (expect longer load time in this case).
$ renfe-cli -h
Usage: renfe-cli [options]
Options:
-f ORIGIN Set From origin station
-t DESTINATION Set To destination station
-d, --day DAY Set the Day (default: today's day)
-m, --month MONTH Set the Month (default: today's month)
-y, --year YEAR Set the Year (default: today's year)
-s, --sort Option to sort the timetable by Duration
-c, --cercanias Option to search over Renfe Cercanías
-h, --help Print this help menu
Getting the timetable
Let's show an example of minimal inputs (origin and destination stations) with specific date and default GTFS dataset:
$ renfe-cli -f girona -t "puerta de atocha" -d 30
Loading default GTFS data from Renfe web - Alta velocidad, Larga distancia y Media distancia
Provided input 'girona' does a match with 'Estación de tren Girona'
Provided input 'puerta de atocha' does a match with 'Estación de tren Madrid-Puerta de Atocha'
Today is: 2024-9-29
Searching timetable for date: 2024-9-30
Origin station: Estación de tren Girona
Destination station: Estación de tren Madrid-Puerta de Atocha
=========================TIMETABLE=========================
Train | Departure | Arrival | Duration
-----------------------------------------------------------
AVLO | 05:46 | 09:20 | 03:34
-----------------------------------------------------------
AVE | 06:41 | 10:10 | 03:29
-----------------------------------------------------------
AVE | 08:11 | 11:45 | 03:34
-----------------------------------------------------------
AVE INT | 11:59 | 15:45 | 03:46
-----------------------------------------------------------
AVE | 15:11 | 19:12 | 04:01
-----------------------------------------------------------
AVE | 17:51 | 21:45 | 03:54
===========================================================
Let's show an example using Renfe Cercanías GTFS dataset:
$ renfe-cli -f chamartín -t "tres cantos" -c
Loading Cercanías GTFS data from Renfe web - long load time
Provided input 'chamartín' does a match with 'Station { name: "Estación de tren Madrid-Chamartín-Clara Campoamor", id: "17000" }'
Provided input 'tres cantos' does a match with 'Station { name: "Estación de tren Tres Cantos (apt)", id: "17004" }'
Today is: 2024-10-2
Searching timetable for date: 2024-10-2
Origin station: Estación de tren Madrid-Chamartín-Clara Campoamor
Destination station: Estación de tren Tres Cantos (apt)
=========================TIMETABLE=========================
Train | Departure | Arrival | Duration
-----------------------------------------------------------
C4b | 05:06 | 05:22 | 00:16
-----------------------------------------------------------
C4b | 05:38 | 05:55 | 00:17
-----------------------------------------------------------
C4b | 06:10 | 06:27 | 00:17
-----------------------------------------------------------
.........
.........
-----------------------------------------------------------
C4b | 21:56 | 22:13 | 00:17
-----------------------------------------------------------
C4b | 22:20 | 22:37 | 00:17
-----------------------------------------------------------
C4b | 23:16 | 23:33 | 00:17
===========================================================
Usage (Library)
renfe-cli
can be imported as a python package into your project, offering utilities when willing to deal with the Renfe search web site.
$ python
Python 3.12.6 (main, Sep 8 2024, 13:18:56) [GCC 14.2.1 20240805] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import renfe_cli
>>> renfe = renfe_cli.
renfe_cli.Renfe() renfe_cli.Schedule( renfe_cli.Station( renfe_cli.main() renfe_cli.renfe_cli
>>> renfe = renfe_cli.Renfe()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Renfe.__new__() missing 1 required positional argument: 'cercanias'
>>> renfe = renfe_cli.Renfe(False)
Loading default GTFS data from Renfe web - Alta velocidad, Larga distancia y Media distancia
GTFS data:
Read in 2171 ms
Stops: 793
Routes: 644
Trips: 4150
Agencies: 1
Shapes: 0
Fare attributes: 0
Feed info: 0
>>> renfe.filter_station("madrid")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Provided input 'madrid' does match with '[Station { name: "Estación de tren Madrid-Puerta de Atocha", id: "60000" }, Station { name: "Estación de tren Madrid - Atocha Cercanias", id: "18000" }, Station { name: "Estación de tren Madrid-Principe Pio", id: "10000" }, Station { name: "Estación de tren Madrid-Ramon Y Cajal", id: "97201" }, Station { name: "Estación de tren Madrid-Nuevos Ministerios", id: "18002" }, Station { name: "Estación de tren Madrid-Chamartin", id: "17000" }, Station { name: "Estación de tren Madrid-Recoletos", id: "18001" }]' -> There must be ONLY one match
>>> renfe.filter_station("girona")
Provided input 'girona' does a match with 'Station { name: "Estación de tren Girona", id: "79300" }'
<builtins.Station object at 0x77f04173d070>
>>> renfe.print_timetable()
No schedules available...won't print timetable.
>>> renfe.set_train_schedules("79300", "60000", 30, 9, 2024, False)
>>> renfe.print_timetable()
=========================TIMETABLE=========================
Train | Departure | Arrival | Duration
-----------------------------------------------------------
AVLO | 05:46 | 09:20 | 03:34
-----------------------------------------------------------
AVE | 06:41 | 10:10 | 03:29
-----------------------------------------------------------
AVE | 08:11 | 11:45 | 03:34
-----------------------------------------------------------
AVE INT | 11:59 | 15:45 | 03:46
-----------------------------------------------------------
AVE | 15:11 | 19:12 | 04:01
-----------------------------------------------------------
AVE | 17:51 | 21:45 | 03:54
===========================================================
>>> ...
Contribute or Report with Issues
If Renfe's GTFS dataset is being kept not up to date or you find any issue to be fixed or nice enhancements to have, please: create an issue.
Development
This project makes use of Rust bindings for the Python interpreter thanks to pyo3. It is already available as a dependency.
To develop, build and publish, this project makes use of maturin project. See usage.
Example of first time working with this repository:
$ git clone https://github.com/gerardcl/renfe-cli.git && cd renfe-cli
$ python -m venv .venv
$ . .venv/bin/activate
$ pip install -U pip
$ pip install -U maturin
$ maturin develop
🔗 Found pyo3 bindings with abi3 support for Python ≥ 3.7
🐍 Not using a specific python interpreter
📡 Using build options features from pyproject.toml
Compiling renfe-cli v5.1.0 (/path/to/renfe-cli)
Finished dev [unoptimized + debuginfo] target(s) in 7.07s
📦 Built wheel for abi3 Python ≥ 3.7 to /tmp/.tmpDsjowL/renfe_cli-5.1.0-cp37-abi3-linux_x86_64.whl
🛠 Installed renfe-cli-5.1.0
Maturin takes care of compiling the rust code, generating the bindings for python and installing the package for local use (as library or binary/CLI).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file renfe_cli-5.1.0.tar.gz
.
File metadata
- Download URL: renfe_cli-5.1.0.tar.gz
- Upload date:
- Size: 26.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cdec17a735bd4a87936130f57a48c6ba4f24fbe7c6820041f0e19a7dd86e60c |
|
MD5 | 2c6cbc64992522eeb4c2fb0862e037bb |
|
BLAKE2b-256 | 86a3e040d1ed2af0880491b3fd6e411dd17da742c7bb0acdc5650d4282defeb1 |
File details
Details for the file renfe_cli-5.1.0-cp37-abi3-win_amd64.whl
.
File metadata
- Download URL: renfe_cli-5.1.0-cp37-abi3-win_amd64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.7+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3963a90e99e1c5682e78bcc5005a3bf51437325be49883aaff46f629c7e2cd4 |
|
MD5 | 0fc2b4b5e7186112414998a0176ff12a |
|
BLAKE2b-256 | 5bb50d5605c40aac2cb9524a24d6b5c9baadffec918b97852ece65db7f2e68e6 |
File details
Details for the file renfe_cli-5.1.0-cp37-abi3-win32.whl
.
File metadata
- Download URL: renfe_cli-5.1.0-cp37-abi3-win32.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.7+, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e3ce6e10cb996098c47150f77104181b0881bb9eb764086178d5bd0f13ea9d0 |
|
MD5 | 95c37221e6adcadaa0653f690299a331 |
|
BLAKE2b-256 | 47bec4e2058461a3c002779f26b7eba06ab3c722308cc643d41865eb4cda1e99 |
File details
Details for the file renfe_cli-5.1.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: renfe_cli-5.1.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.4 MB
- Tags: CPython 3.7+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d3144f4165aa85e9b4af0075148ac64659fc5631ba02fa5621784b9dc3848f1 |
|
MD5 | 0a5a43ca98622fee43ef3252115a18ec |
|
BLAKE2b-256 | beb611ab5a2ed3631e1ef3231bc70e2572b1d1470b5622bd54af6e9af09edf59 |
File details
Details for the file renfe_cli-5.1.0-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
.
File metadata
- Download URL: renfe_cli-5.1.0-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
- Upload date:
- Size: 2.4 MB
- Tags: CPython 3.7+, manylinux: glibc 2.17+ s390x
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c26d3a83fb71b91ffbda271624ac1efe33eebfff5f9e8c9bc880c3380ff7809 |
|
MD5 | 01751ecc0c63a535f76f48a45d5987f3 |
|
BLAKE2b-256 | c6bb12687d1de059ad883af723bb77e44385101be8a4b8333ed99e0aa1ea25d4 |
File details
Details for the file renfe_cli-5.1.0-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
.
File metadata
- Download URL: renfe_cli-5.1.0-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.7+, manylinux: glibc 2.17+ ppc64le
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3b85cf9cfad268241624679f93d4bd2c3553160caf104504b0e494056b0a8a7 |
|
MD5 | 26df04102cd876e3ed3fc9cca54289cc |
|
BLAKE2b-256 | c39a11bca939207e87e1fb621360d03593d772f7f8428679f7273fcdd99a7de6 |
File details
Details for the file renfe_cli-5.1.0-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: renfe_cli-5.1.0-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.7+, manylinux: glibc 2.17+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a41a4c1b7fcf22f0f3321d1483d105f3be6262455df30e003fd3e8fdd27870d |
|
MD5 | 19eb92339a9ad73412ff67d634b8aec2 |
|
BLAKE2b-256 | 6d1cbc9d33676cc0e18fdef277c8c85f7ebcbb685294d2f8b12d039d43224546 |
File details
Details for the file renfe_cli-5.1.0-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
.
File metadata
- Download URL: renfe_cli-5.1.0-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.7+, manylinux: glibc 2.17+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dff9f44bc40211be6d8d77548228b102a8b56244ebe4132c2a80f6676863bf70 |
|
MD5 | 8f29a44c6278eab23bfbbbdbf012c192 |
|
BLAKE2b-256 | 68566f00f769826b0505d9f7c66d2ff6c7be5c5fc8107c0bd68d75ac9e762487 |
File details
Details for the file renfe_cli-5.1.0-cp37-abi3-macosx_11_0_arm64.whl
.
File metadata
- Download URL: renfe_cli-5.1.0-cp37-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.7+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7d8be2de982209e2c6cd2d109610abc3359c11ecc7947ac293a4127450e88a2 |
|
MD5 | 662c4771683e14aeb1531a895849fe55 |
|
BLAKE2b-256 | 329fcbeda1d6937f850ee9e6a449a72231db4ac3e0823bb2f542dc030c4457da |
File details
Details for the file renfe_cli-5.1.0-cp37-abi3-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: renfe_cli-5.1.0-cp37-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.7+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e4f949421b3a3bf9d09d9d32a522547d4ceb4ec967c367465538e081d4f73a0 |
|
MD5 | 0d6df9e5bbeb9011652fd3d6e377e4fb |
|
BLAKE2b-256 | 442f1f7baabc744561da05449d614b4ea3fc2b710379957d84bc345c9debf849 |