Read-only mirror of https://github.com/openTdataCH/ondemand-hrdf-converter — SBB. Issues & pull requests at the source.
  • Python 99.8%
  • Dockerfile 0.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2025-06-26 15:01:14 +02:00
resources bugfix + more infotexts 2025-06-20 08:53:49 +02:00
.gitignore Merge remote-tracking branch 'origin/main' into feature/dockerization 2025-05-05 13:00:17 +02:00
Dockerfile update Dockerfile 2025-04-25 14:18:27 +02:00
LICENSE First commit 2025-04-22 12:17:11 +02:00
main.py fixing treatement of flexiblelinetype 2025-06-26 15:01:14 +02:00
README.md Proper transport operator references 2025-06-17 11:14:35 +02:00
requirements.txt First commit 2025-04-22 12:17:11 +02:00

On-Demand NeTEx to HRDF converter

This tool allows to convert the Swiss NeTEx exports containing the on-demand data into the proprietary HRDF format. Containing only the On-Demand data.

To learn more about:

Libraries

You need to install the following additional libraries:

Creating an exe

Simply use pyinstaller: https://pyinstaller.org/en/stable/

pyinstaller -F main.py

To include the resources folder in the exe, and not require it to be in the same folder as the main.exe. This also implies not being able to change those file(s).

pyinstaller -F --add-data="resources:resources" main.py

Using the tool

To run the code you can pass 4 parameters:

  • (--offers) the offers to limit the conversion to (if you know them)
    • Default: "" (all offers)
  • (--from_url) the url to read the NeTEx file from
  • (--from_folder) if you have the input in a folder then you can provide the folder to read from - if given we ignore the url
    • Default: "" (no from_folder)
  • (--to_folder) the folder to write the converted HRDF files to. We assume the folder already exists!
    • Default: "output" - will be created if it does not exist
  • (--keep_output) whether or not to keep the tmp and output folders after code execution
    • Default: True
  • (--ftp) the parameters of the ftp to upload the data to, a quadruple (URL, User, Password, Path)
    • Default: None
    • IMPORTANT: the URL should contain the protocol (sftp or ftps) and if not default port 21 also the port, e.g., ": 33".
    • ALSO: The path is the relative directory path you want the zip to be uploaded to.
    • We do not support the insecure FTP protocol
    • If this parameter is not given the zip file will remain locally
  • (--output_format) either utf-8 or ansi. However, there's an issue with ansi and not all files are properly exported.

Example if you want to use the defaults:

python main.py 

Example with parameters:

python main.py --offers "Publicar Appenzell" --from_folder "C:\\somewhere\\netex" --to_folder "C:\\somehwere\\hrdf" --ftp "sftp://abc.com:33,user,password,path"

What the code does

  1. Create all HRDF files required to model on-demand
  2. Loads the NeTEx-On-Demand data from the following sources (if not stated otherwise): https://data.opentransportdata.swiss/dataset/netex_tt_odv/permalink
  3. If a folder is given the NeTEx-On-Demand data is loaded from there
  4. To store the downloaded file and for the purpose of unzipping we create a "tmp" folder where the code is run
  5. Traverse the NeTEx file and fill in the HRDF-files accordingly
  6. Zip the resulting folder (the file will be named <todays_date>_hrdf_odv)
  7. (optionally) Upload the Zip file to the given FTP Server
  8. If data was loaded from url, remove it, the temp folder and if output folder was created remove that as well.
  9. If there was an FTP upload also remove the zip file

Caveats:

  • The file zugart are hard-coded
  • Certain information required for a proper HRDF are momentarily not part of the Swiss NeTEx data. We are working on changing that.