-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmirror.sh
executable file
·66 lines (53 loc) · 1.82 KB
/
mirror.sh
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# GTFS mirroring tool. This allows us to keep the GTFS data from Adelaide
# Metro into a revision control system (so we could look up historical data).
#
# Copyright 2011 Michael Farrell <http://micolous.id.au>
#
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.
DATA_ZIP="http://adelaidemetro.com.au/GTFS/google_transit.zip"
DATA_ZIPFILENAME="google_transit.zip"
function get_release_isodate {
# Gets the ISO8601 date of the release
D=`grep "Release: " "$1" | head -n1 | cut -d" " -f2 | sed 's#-#/#g'`
if [ -n "$D" ]; then
Y=`echo $D | cut -d/ -f3`
M=`echo $D | cut -d/ -f2`
A=`echo $D | cut -d/ -f1`
echo "${Y}-${M}-${A}:${1}"
else
# Cannot parse
echo "0000-00-00:${1}"
fi
}
function get_release_dates {
find gtfs/ -name 'release\ notes*.txt' | while read i
do
get_release_isodate "$i"
done
}
# Create the target folder
mkdir -p "gtfs"
# Delete old release notes from the folder
rm -f gtfs/release\ notes*.txt
# Download data archive
# Normally -O would be used here, but it doesn't work in combination with -N.
# (see wget man page for details)
wget -N "${DATA_ZIP}"
# Extract the data into the data folder
unzip -oujL "${DATA_ZIPFILENAME}" -d gtfs
# Add files to commit
git add gtfs/*.txt
# Commit
DATE="`date`"
HEADER="New data from upstream source on ${DATE}\n"
# Find the newest release notes and construct a commit message from them
NEW_NOTES=`get_release_dates | sort -r | head -n1 | cut -d: -f2`
MSG=`echo -e $HEADER | cat - "${NEW_NOTES}"`
git commit -am "${MSG}"
# Push downstream to github
git push origin master