-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupdate-all
executable file
·41 lines (34 loc) · 1.21 KB
/
update-all
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
set -e
read -p "Username: " USERNAME
read -s -p "Password: " PASSWORD
TOKEN=$(curl 'https://opendata.nationalrail.co.uk/authenticate' \
--data-urlencode "username=$USERNAME" \
--data-urlencode "password=$PASSWORD" | jq -r .token)
curl 'https://opendata.nationalrail.co.uk/api/staticfeeds/2.0/fares' -H "X-Auth-Token: $TOKEN" --output fares.zip
curl 'https://opendata.nationalrail.co.uk/api/staticfeeds/3.0/timetable' -H "X-Auth-Token: $TOKEN" --output timetable.zip
FARE_DIR=fare-data-$(unzip -l fares.zip | grep TOC | perl -pe's/.*FAF(\d+).*/$1/')
TIMETABLE_DIR=timetable-data-$(unzip -l timetable.zip | grep MCA | perl -pe's/.*TTF(\d+).*/$1/')
PROCESS=""
if [ ! -e $FARE_DIR ]; then
PROCESS=1
unzip -d $FARE_DIR fares.zip
fi
rm fares.zip
if [ ! -e $TIMETABLE_DIR ]; then
PROCESS=1
unzip -d $TIMETABLE_DIR timetable.zip
fi
rm timetable.zip
if [ -n "$PROCESS" ]; then
set -x
source venv/bin/activate
python parse-tocs $FARE_DIR
python parse-stations $FARE_DIR
python parse-restrictions $FARE_DIR
python parse-fares $FARE_DIR
python parse-ndf $FARE_DIR
python parse-trains $FARE_DIR $TIMETABLE_DIR
python merge-fares-ndf $FARE_DIR
git add data/fares
fi