Giter Club home page Giter Club logo

trainline-python's Introduction

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

trainline-python's People

Contributors

alxch- avatar antoinevth avatar raphael0202 avatar tducret avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trainline-python's Issues

Does it work for international train stations / Thalys / Eurostar?

Hey,

I tried to query for prices between Paris and Antwerp but got the following error:

➜  trainline_cli.py -d Paris -a Antwerpen-Centraal -n 3d
Traceback (most recent call last):
  File "/usr/local/bin/trainline_cli.py", line 92, in <module>
    main()
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/bin/trainline_cli.py", line 63, in main
    to_date=to_date)
  File "/usr/local/lib/python3.7/site-packages/trainline/__init__.py", line 567, in search
    folders = _get_folders(search_results_obj=j)
  File "/usr/local/lib/python3.7/site-packages/trainline/__init__.py", line 618, in _get_folders
    trip_obj_list = _get_trips(search_results_obj)
  File "/usr/local/lib/python3.7/site-packages/trainline/__init__.py", line 651, in _get_trips
    segment_obj_list = _get_segments(search_results_obj)
  File "/usr/local/lib/python3.7/site-packages/trainline/__init__.py", line 694, in _get_segments
    comfort_class_obj_list = _get_comfort_classes(search_results_obj)
  File "/usr/local/lib/python3.7/site-packages/trainline/__init__.py", line 766, in _get_comfort_classes
    comfort_class_obj = ComfortClass(dict_comfort_class)
  File "/usr/local/lib/python3.7/site-packages/trainline/__init__.py", line 452, in __init__
    expected_type, expected_param, type(param_value)))
TypeError: Type <class 'dict'> expected for options, <class 'NoneType'> received

Comfort Class

I didn't find how to ask for a specific comfort class or to get this info in the results.

Is it possible ?

If it isn't possible, it would be a great feature !

All requests are crashing

  • trainline version: 0.1.0
  • Python version: 3.7
  • Operating System: macOS

Description

All requests return the same error:
requests.exceptions.ConnectionError: Status code 400 for url https://www.trainline.eu/api/v5_1/search
{"error":{"code":"no_results","message":{}}}

What I Did

It used to work very well, but for the last few days, no requests I've tried have seem to work.
I tried to use both the trainline_cli.py file and the Docker Image (downloaded today November 24th)

trainline --departure="Toulouse" --arrival="Nantes" --next=12hours
trainline --departure="Bordeaux" --arrival="Lille" --next=12hours

Complete Traceback :
Traceback (most recent call last):
  File "/app/bin/trainline_cli.py", line 104, in <module>
    main()
  File "/app/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/app/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/app/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/app/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/app/bin/trainline_cli.py", line 75, in main
    transportation_mean=transport)
  File "/app/trainline/__init__.py", line 606, in search
    passenger_list=passenger_list)
  File "/app/trainline/__init__.py", line 129, in search
    ret = c._post(url=_SEARCH_URL, post_data=post_data)
  File "/app/trainline/__init__.py", line 83, in _post
    status=ret.status_code, url=url, content=ret.text))
requests.exceptions.ConnectionError: Status code 400 for url https://www.trainline.eu/api/v5_1/search
{"error":{"code":"no_results","message":{}}}

UnicodeDecodeError

  • trainline version: 0.06
  • Python version: 3.7.1
  • Operating System: win 10 64bits anaconda (package installé en pip)

Description

Quand je run l'exemple

# -*- 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())

j'obtiens

Traceback (most recent call last):

  File "<ipython-input-12-7e6daafd5aef>", line 1, in <module>
    runfile('C:/Users/qchat/Desktop/test.py', wdir='C:/Users/qchat/Desktop')

  File "C:\Users\qchat\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 704, in runfile
    execfile(filename, namespace)

  File "C:\Users\qchat\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/qchat/Desktop/test.py", line 8, in <module>
    to_date="15/05/2019 21:00")

  File "C:\Users\qchat\Anaconda3\lib\site-packages\trainline\__init__.py", line 547, in search
    departure_station_id = get_station_id(departure_station)

  File "C:\Users\qchat\Anaconda3\lib\site-packages\trainline\__init__.py", line 524, in get_station_id
    _STATION_DB = _station_to_dict(_STATIONS_CSV)

  File "C:\Users\qchat\Anaconda3\lib\site-packages\trainline\__init__.py", line 879, in _station_to_dict
    csv_content = _read_file(filename)

  File "C:\Users\qchat\Anaconda3\lib\site-packages\trainline\__init__.py", line 874, in _read_file
    read_data = f.read()

  File "C:\Users\qchat\Anaconda3\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]

UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 313652: character maps to <undefined>


Sinon, très bonne idée ce package python :)

SNCF requires (young) card number

What I Did

When executing a search for a SNCF connection with a young card, the Trainline server now returns:

{"errors":{"passengers":["La carte Carte Avantage Jeune n’est pas valide : Le numéro de carte doit être rempli(e)"]}}

Seems that SNCF is now requesting the card number as well (as I saw on their website).
I manually added a "number" field to the card stored in the Passenger object, as it is done for TGV MAX card, which solved the problem.

403 error systematically

  • trainline version: 0.1.2
  • Python version: Python 3.7.12
  • Operating System: Ubuntu 22.04

Description

import trainline

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

print(results.csv())

What I Did


ConnectionError: Status code 403 for url https://www.trainline.eu/api/v5_1/search
{"url":"https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAlKNr1QJizNQAmE2fxQ==&cid=8xF~oUzPNL-oYo39IbiOCm6bsa07Cczk449-C5qcIlqEYLyQRKMnipNjrzunDh7j4fAy0_YdSq~qhEPSd0w73WxlGhLCy~qtybii6zkYYvkzpIUBELc3A9GvOjVIaOp&referer=HTTPS%3A%2F%2Fwww.trainline.eu%2Fapi%2Fv5_1%2Fsearch&hash=E1950F58FF4C3B67C237DE42A4D080&t=fe&s=35668&e=6418b8f16dabeec967beb95265b8b63962e2c4166ca4b41593d3e90c3995fb34"}

[suggestion] i wanted an option to specify a date

A little suggestion to specify a start date (instead of now).
Too, in python, code is clear enough not to comment every lines.

ヽ(´ー`)┌
--- trainline_cli.py	2021-02-17 18:40:51.312990416 +0100
+++ trainline_cli.py	2021-02-17 19:17:46.396430200 +0100
@@ -4,9 +4,16 @@
 """CLI tool for trainline."""
 import click
 import trainline
+import re
 from datetime import datetime, timedelta
 
 # Usage : trainline_cli.py --help
+DATE_FORMAT="%d/%m/%Y %H:%M"
+KNOWN_DATE_FORMATS=list(set([
+    DATE_FORMAT,
+    "%d/%m/%Y", "%d/%m/%Y %H:%M",
+    '%Y-%m-%d', '%Y-%m-%d %H:%M'
+]))
 
 
 @click.command()
@@ -24,9 +31,16 @@
     required=True,
 )
 @click.option(
+    '--start', '-s',
+    type=click.DateTime(formats=KNOWN_DATE_FORMATS),
+    help='start date',
+    default=datetime.now().strftime(DATE_FORMAT),
+    show_default=True,
+)
+@click.option(
     '--next', '-n',
     type=str,
-    help='period of search from now \
+    help='period of search from start date \
 (example : 1day, 2days, 3d, 1hour, 2hours, 3h)',
     default='3hours',
     show_default=True,
@@ -43,21 +57,16 @@
     is_flag=True,
     help='verbose mode',
 )
-def main(departure, arrival, next, transport, verbose):
+def main(departure, arrival, start, next, transport, verbose):
     """ Search trips with Trainline and returns it in csv """
 
-    # Get current datetime > from_date
-    from_date_obj = datetime.now()
-
-    # Decode duration (ex : 1day => timedelta(days=1))
+    from_date = start
     delta = _decode_next_param(next)
-
-    # Calculate the end date > to_date
-    to_date_obj = from_date_obj + delta
+    to_date = from_date + delta
 
     # Convert the datetime objects to strings
-    from_date = from_date_obj.strftime("%d/%m/%Y %H:%M")
-    to_date = to_date_obj.strftime("%d/%m/%Y %H:%M")
+    from_date = from_date.strftime(DATE_FORMAT)
+    to_date = to_date.strftime(DATE_FORMAT)
 
     if transport == "any":
         transport = None

I can't install trainline using pip3

  • trainline version: latest
  • Python version: 3.8
  • Operating System: OSX

Description

I can't install trainline using pip3

What I Did

Collecting trainline
  Using cached trainline-0.1.1.tar.gz (279 kB)
    ERROR: Command errored out with exit status 1:
     command: /usr/local/opt/[email protected]/bin/python3.8 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/lr/0m8k26c90rs3zfhdq2018rt40000gn/T/pip-install-654dg46b/trainline/setup.py'"'"'; __file__='"'"'/private/var/folders/lr/0m8k26c90rs3zfhdq2018rt40000gn/T/pip-install-654dg46b/trainline/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/lr/0m8k26c90rs3zfhdq2018rt40000gn/T/pip-pip-egg-info-dsamo052
         cwd: /private/var/folders/lr/0m8k26c90rs3zfhdq2018rt40000gn/T/pip-install-654dg46b/trainline/
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/lr/0m8k26c90rs3zfhdq2018rt40000gn/T/pip-install-654dg46b/trainline/setup.py", line 22, in <module>
        requirements = [str(ir.req) for ir in install_reqs]
      File "/private/var/folders/lr/0m8k26c90rs3zfhdq2018rt40000gn/T/pip-install-654dg46b/trainline/setup.py", line 22, in <listcomp>
        requirements = [str(ir.req) for ir in install_reqs]
    AttributeError: 'ParsedRequirement' object has no attribute 'req'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.```

Tarif TGVmax non pris en compte

  • trainline version: 0.0.8

Hey,

First of all, very nice and usefull code !!
I have an issue when I specify my TGVmax id card, I get all the train of my period except all of them which are set at 0.0€.
Do you know how to list even a train with a price set to 0.0€ ? Which are them I looking for.
I tried to modify the min_price and the filter loop, but can't find a solution.

Thanks a lot,
Regards.

TGVMax card's number is not sufficient

  • trainline version: 0.1.1
  • Python version: 3.8.6
  • Operating System: Windows

Description

Trying to search some travels with TGVMax card, it seems that it is no more sufficient to give the card's number.
It reports an error, asking to create an account : {"errors":{"passengers":["Veuillez créer un compte pour réserver vos voyages TGVmax"]}}.
It should give me the available trains.

What I Did

    TGVMaxPassenger = trainline.Passenger(birthdate="01/01/1998")
    TGVMaxPassenger.add_special_card(trainline.TGVMAX, "MyCardNumber")
    results = trainline.search(
    passengers=[TGVMaxPassenger],
	departure_station='Lyon',
	arrival_station='Paris',
	from_date="10/10/2020 12:00",
	to_date="11/10/2020 12:00")

And it raised the following error :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\trainline\__init__.py", line 602, in search
    ret = t.search(
  File "PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\trainline\__    ret = c._post(url=_SEARCH_URL, post_data=post_data)
init__.py", line 81, in _post
    raise ConnectionError(
requests.exceptions.ConnectionError: Status code 422 for url https://www.trainline.eu/api/v5_1/search
{"errors":{"passengers":["Veuillez créer un compte pour réserver vos voyages TGVmax"}}

PS : Thank's a lot for this beautiful library

Don't use mutable function parameters

In Passenger.__init__, a mutable parameter is used for cards, which leads to the following bug:

import trainline

passenger = trainline.Passenger(birthdate="12/12/1999")
passenger.add_special_card(trainline.TGVMAX, "YourCardNumber")
passenger_2 = trainline.Passenger(birthdate="12/12/1999")


KeyError                                  Traceback (most recent call last)
<ipython-input-1-7fa648000ffe> in <module>
      3 passenger = trainline.Passenger(birthdate="12/12/1999")
      4 passenger.add_special_card(trainline.TGVMAX, "YourCardNumber")
----> 5 passenger_2 = trainline.Passenger(birthdate="12/12/1999")

~/git_core/trainline-python/trainline/__init__.py in __init__(self, birthdate, cards)
    320             if card not in _AVAILABLE_CARDS:
    321                 raise KeyError("Card '{}' unknown, [{}] available".format(
--> 322                     card, ",".join(_AVAILABLE_CARDS)))
    323         self.cards = cards
    324 

KeyError: "Card '{'reference': 'SNCF.HappyCard', 'number': 'YourCardNumber'}' unknown, [SNCF.CarteEnfantPlus,SNCF.Carte1225,SNCF.CarteEscapades,SNCF.CarteSenior] available"

Crash sur certaines dates

  • trainline version: last
  • Python version: Python 3.5.3
  • Operating System: Debian

Description

Bonjour, j'essaye le script sur différentes dates, certaines comme aujourd'hui fonctionnent mais certaines dans le futur non. Le programme crash

What I Did

Voici mon code
`# -- coding: utf-8 --
import trainline

Yann = trainline.Passenger(birthdate="04/07/1994")

results = trainline.search(
passengers=[Yann],
departure_station="paris",
arrival_station="nice",
from_date="21/06/2019 08:00",
to_date="21/06/2019 21:00")

print(results.csv())`

et voici l'erreur quand je lance la commande
Traceback (most recent call last): File "test_trainline/test2.py", line 11, in <module> to_date="21/06/2019 21:00") File "/home/yann/.local/lib/python3.5/site-packages/trainline/__init__.py", line 596, in search folders = _get_folders(search_results_obj=j) File "/home/yann/.local/lib/python3.5/site-packages/trainline/__init__.py", line 648, in _get_folders trip_obj_list = _get_trips(search_results_obj) File "/home/yann/.local/lib/python3.5/site-packages/trainline/__init__.py", line 681, in _get_trips segment_obj_list = _get_segments(search_results_obj) File "/home/yann/.local/lib/python3.5/site-packages/trainline/__init__.py", line 724, in _get_segments comfort_class_obj_list = _get_comfort_classes(search_results_obj) File "/home/yann/.local/lib/python3.5/site-packages/trainline/__init__.py", line 796, in _get_comfort_classes comfort_class_obj = ComfortClass(dict_comfort_class) File "/home/yann/.local/lib/python3.5/site-packages/trainline/__init__.py", line 478, in __init__ for extra in self.extras: TypeError: 'NoneType' object is not iterable

En revanche, si je change from_date "21/06/2019 08:00" pour "10/06/2019 08:00" et to_date "21/06/2019 21:00" pour "10/06/2019 21:00", ca fonctionne bien.
Très bizarre car les dates on l'air pourtant bonne...

Sinon bravo pour ton travail, j'ai regardé ton code, c'est très intéressant! :)
Merci d'avance!

CAPCHA Error

  • trainline version: latest
  • Python version: Python 3.9.7
  • Operating System: macOS Monterey 12.0.1

Description

I have an error when i run this command :

~ % docker run -it --rm thibdct/trainline --departure="Toulouse" --arrival="Bordeaux" --next=12hours
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
Traceback (most recent call last):
File "/app/bin/trainline_cli.py", line 104, in
main()
File "/app/click/core.py", line 764, in call
return self.main(*args, **kwargs)
File "/app/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/app/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/app/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/app/bin/trainline_cli.py", line 75, in main
transportation_mean=transport)
File "/app/trainline/init.py", line 606, in search
passenger_list=passenger_list)
File "/app/trainline/init.py", line 129, in search
ret = c._post(url=_SEARCH_URL, post_data=post_data)
File "/app/trainline/init.py", line 83, in _post
status=ret.status_code, url=url, content=ret.text))
requests.exceptions.ConnectionError: Status code 403 for url https://www.trainline.eu/api/v5_1/search
{"url":"https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAr6iE4AJKYw4AWKiFGA==&cid=Qbdi60vxNjrCR_UO36tp0APJHQ_iwdN.4iMl9FpBj~e9_9tSqHhvYZs0VwG43PYeMD9Drei0Uj0jn34rWgnYzLl1P0cjqyTwuHb4O.EqKm&referer=HTTPS%3A%2F%2Fwww.trainline.eu%2Fapi%2Fv5_1%2Fsearch&hash=E1950F58FF4C3B67C237DE42A4D080&t=fe&s=35668"}

What I Did

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

Thanks for your help

Duplicates in stations_mini.csv

  • trainline version: 0.0.8
  • Python version: 3.7
  • Operating System: MacOS

Description

stations_mini.csv is generated from the stations.csv from Trainline, but it seems that this file contains duplicates. For example, there seems to be two stations for Rennes which are duplicated in the stations.csv file too: 5055 (https://github.com/tducret/trainline-python/blob/master/trainline/stations_mini.csv#L3807) and 5097 (https://github.com/tducret/trainline-python/blob/master/trainline/stations_mini.csv#L3833). However, the get_station_id returns the first occurence in the stations_mini.csv, which sometimes returns no result from the trainline API.
Some stations are marked as suggestable in stations.csv. From what I understand, Trainline API will result results only for these stations.
I am going to open a PR to generate stations_mini.csv only for stations having the is_suggestable set to True. The README (https://github.com/trainline-eu/stations) indicates that is_suggestable means : Specify if the user can input this station.

What I Did

user = trainline.Passenger(birthdate="01/01/1996", cards=[trainline.JEUNE])
s = trainline.search( passengers=[user], departure_station="Paris", arrival_station="Rennes", from_date="18/06/2019 11:00", to_date="18/06/2019 15:00")

I got:

Status code 400 for url https://www.trainline.eu/api/v5_1/search
{"error":"Nous n’avons trouvé aucun trajet à cet horaire.","code":"no_results"}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.