Solved

any way to export 'my trip' in machine readable form?

  • 10 September 2022
  • 6 replies
  • 359 views

I expect the answer to this is “no” but …

Does anyone know if there’s a way to export the data from “my trip” from a mobile pass in some kind of machine-readable form, e.g. something that can be imported into Excel?

icon

Best answer by rvdborgt 10 September 2022, 22:28

View original

6 replies

Userlevel 7
Badge +9

Would be interesting indeed to have that. But as far as I know, the only possibilities are "Share as Link” and "Share as image” in the app. Maybe you can do something with "Share as Link”?

Userlevel 4
Badge +2

Sadly the answer here is “no”. The best we can offer at this point is to take a screen shot or to send the link. I'll pass along this feedback though and keep this thread updated if an exportable PDF function can be implemented - thanks for the suggestion! :)

@Claudi. A PDF would certainly be helpful for some people but isn’t what my friend was after. He wanted something that he could read into Microsoft Excel or similar - i.e. one train = one row in the sheet. That would need either a proper Microsoft Excel file or a .CSV file which Excel can import.

@rvdborgt Thank you for the suggestion about the link.

For anyone reading finding this via search in the future, if you know what you’re doing then you can ‘wget’ the ‘Share as Link’ URL. The resulting HTML file includes the train and trip data in JSON format. It fails the Excel ‘read JSON’ feature but it may be possible to fix that. I’ve not got that far yet.

I build a small python script to extract the the data from the link. It creates a json file from the full data and a csv file with all travels with a couple of attributes including departure and arrival time, origin and destination with country, duration of each travel and the interchanges.

https://github.com/Peer222/interrail_route

I build a small python script to extract the the data from the link. It creates a json file from the full data and a csv file with all travels with a couple of attributes including departure and arrival time, origin and destination with country, duration of each travel and the interchanges.

https://github.com/Peer222/interrail_route

Hello pebadu,
Thanks a lot for sharing your python script. I tried to run it a few times, but I keep recieving an error “json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 1994 (char 1993)” (disclaimer: I’m very new to python, so I might be doing a simple mistake somewhere). I tried to consult the issue with ChatGPT, but it didn’t really help me.
Can I ask you to have a look at the error and possibly indicate where the problem is? Of course only in case you have time and are willing to dedicate some of it to this issue. Perhaps it might be helpful for other in the future :).


I’m copying my python log below (and also attaching as a printscreen).
Note: I found out, that some time after I create the url (with “Share as a link” button in the Interrail app, it expires and doesn’t work anymore. So if anyone reads this some time after being published, it might be better to create your own “fresh” url from the Interrail app, in case you’d like to replicate the case). Thanks upfront!!

 

C:\WINDOWS\system32>python --version

Python 3.11.5

C:\Milan\Ostatni\Personal\Python>python get_route.py --url "https://share.eurailapp.com/share/trip?id=E3EE9070-885E-11EE-8210-775D46DDAD89&type=list&brand=interrail"

Traceback (most recent call last):

  File "C:\Milan\Ostatni\Personal\Python\get_route.py", line 118, in <module>

    data = extract_route(args.url)

           ^^^^^^^^^^^^^^^^^^^^^^^

  File "C:\Milan\Ostatni\Personal\Python\get_route.py", line 14, in extract_route

    payload = json.loads(re.findall("payload\s=\s(\{[^;]+);", html)[0])

              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "C:\Users\mxm\AppData\Local\Programs\Python\Python311\Lib\json\__init__.py", line 346, in loads

    return _default_decoder.decode(s)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "C:\Users\mxm\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py", line 337, in decode

    obj, end = self.raw_decode(s, idx=_w(s, 0).end())

               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "C:\Users\mxm\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py", line 353, in raw_decode

    obj, end = self.scan_once(s, idx)

               ^^^^^^^^^^^^^^^^^^^^^^

json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 1994 (char 1993)

C:\Milan\Ostatni\Personal\Python> 

Hi Milan,

The Regex in extract_route did not handled your payload properly because my assumption was false that a semicolon does not appear in it.

I pushed the bugfix.

Reply