diff options
-rwxr-xr-x | buseir | 31 |
1 files changed, 15 insertions, 16 deletions
@@ -2,9 +2,9 @@ | |||
2 | # Download Bus Eireann data to CSV file cache, and provide useful functions to | 2 | # Download Bus Eireann data to CSV file cache, and provide useful functions to |
3 | # view data | 3 | # view data |
4 | 4 | ||
5 | SITE=https://buseireann.ie | 5 | SITE="https://buseireann.ie" |
6 | CACHE=$XDG_CACHE_HOME/buseir | 6 | CACHE="$XDG_CACHE_HOME/buseir" |
7 | TMP=/tmp/buseir | 7 | TMP="/tmp/buseir" |
8 | 8 | ||
9 | menu() { fzf -m --reverse --height=12; } | 9 | menu() { fzf -m --reverse --height=12; } |
10 | 10 | ||
@@ -13,25 +13,24 @@ readCsv() { | |||
13 | then cat "$1"; | 13 | then cat "$1"; |
14 | else echo "$2" | while read -r key | 14 | else echo "$2" | while read -r key |
15 | do echo "\(\"\|^\|,\)$key\(\"\|$\|,\)" | 15 | do echo "\(\"\|^\|,\)$key\(\"\|$\|,\)" |
16 | done | grep -f - "$1" | 16 | done | grep -f - "$1" |
17 | fi | cut -d, -f "$3" | tr -d \" | 17 | fi | cut -d, -f "$3" | tr -d \" |
18 | } | 18 | } |
19 | 19 | ||
20 | sync() { | 20 | sync() { |
21 | echo Syncing data... | 21 | echo "Syncing data..." |
22 | [ ! -d "$TMP" ] && mkdir -p "$TMP" | 22 | [ ! -d "$TMP" ] && mkdir -p "$TMP" || rm -rf "$TMP"/* |
23 | rm -f "$TMP"/* | 23 | wget -qP "$TMP" "$SITE" "$SITE/inc/proto/bus_stop_points.php" \ |
24 | wget -qP "$TMP" "$SITE" "$SITE"/inc/proto/bus_stop_points.php \ | ||
25 | || (echo "Connection failed!" && exit); | 24 | || (echo "Connection failed!" && exit); |
26 | xmllint --html --xpath \ | 25 | xmllint --html --xpath \ |
27 | "//select[@id='form-fare-finder-service']/option/text()" "$TMP"/index.html 2>/dev/null \ | 26 | "//select[@id='form-fare-finder-service']/option/text()" "$TMP/index.html" 2>"/dev/null" \ |
28 | | sed 's/\s*:\s*/,/; /Select Service/d' > "$TMP"/routes.csv | 27 | | sed 's/\s*:\s*/,/; /Select Service/d' > "$TMP/routes.csv" |
29 | readCsv "$TMP"/routes.csv all 1 | while read -r bus | 28 | readCsv "$TMP/routes.csv" all 1 | while read -r bus |
30 | do echo "$SITE"/inc/proto/fareDestinations.php?fare="$bus"; done \ | 29 | do echo "$SITE/inc/proto/fareDestinations.php?fare=$bus"; done \ |
31 | | wget -q -i - -O - | jq -r '[.fareDestinations[]|.name]|@csv' \ | 30 | | wget -q -i - -O - | jq -r '[.fareDestinations[]|.name]|@csv' \ |
32 | | paste -d, "$TMP"/routes.csv - > "$CACHE"/routes.csv | 31 | | paste -d, "$TMP/routes.csv" - > "$CACHE/routes.csv" |
33 | grep -o "{.*}" "$TMP"/bus_stop_points.php \ | 32 | grep -o "{.*}" "$TMP/bus_stop_points.php" \ |
34 | | jq -r '.bus_stops[]|[.name,.num,.duid,.lat,.lng]|@csv' > "$CACHE"/stops.csv | 33 | | jq -r '.bus_stops[]|[.name,.num,.duid,.lat,.lng]|@csv' > "$CACHE/stops.csv" |
35 | } | 34 | } |
36 | 35 | ||
37 | stops() { | 36 | stops() { |
@@ -39,7 +38,7 @@ stops() { | |||
39 | all) COL=1-;; num) COL=2;; duid) COL=3;; | 38 | all) COL=1-;; num) COL=2;; duid) COL=3;; |
40 | pos) COL=4-5;; *) COL=1;; | 39 | pos) COL=4-5;; *) COL=1;; |
41 | esac | 40 | esac |
42 | readCsv "$CACHE"/stops.csv "$1" "$COL" | 41 | readCsv "$CACHE/stops.csv" "$1" "$COL" |
43 | } | 42 | } |
44 | 43 | ||
45 | printStop() { | 44 | printStop() { |