Client program for rata.digitraffic.fi API. Stores trains and compositions into a local PostgreSQL database.
- NodeJS v14+
- PostgreSQL v10+
- PM2
Install node modules:
npm install
Create a PostgreSQL database.
Then create tables by running init.sql:
psql -d mydb -f init.sql
Open config.js and revise config.DIGITRAFFIC_USER custom header to match your own application.
Create .env file and put DB configuration there:
POSTGRES_HOST=127.0.0.1
POSTGRES_PORT=5432
POSTGRES_DB=mydb
POSTGRES_USER=user
POSTGRES_PASSWORD=pass
node rata-client.js -p
starts polling trains and compositions from digitraffic
or
node rata-client.js -c file
imports archived compositions from json file
or
node rata-client.js -t file
imports archived trains from json file
When you have installed PM2 run this in the main directory:
pm2 start
Create a temp directory:
mkdir temp
cd temp
Create a list of urls to download from https://rata.digitraffic.fi/api/v1/trains/dumps/list.html and then download all files:
xargs -n 1 curl --compressed -O < url_list.txt
Unzip all files:
unzip '*.zip'
Process all trains json files in the directory:
for f in *trains.json; do echo $f; node ../rata-client/rata-client.js -t $f; done