summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCian Bagshaw <cian@cianb.xyz>2023-06-06 01:42:01 +0100
committerCian Bagshaw <cian@cianb.xyz>2023-06-06 01:42:01 +0100
commitdfa7b92e900687967b6049f98e2dfff1aa605e6d (patch)
treed27ebf0269ec2935bed7361e19582634bb83ecfd
parent412241cd24b84aba9868ec8d595f3f083f3860a8 (diff)
downloadbuseir-master.tar.bz2
buseir-master.zip
Fixed quotesHEADmaster
-rwxr-xr-xbuseir31
1 files changed, 15 insertions, 16 deletions
diff --git a/buseir b/buseir
index e72fd24..06c3f37 100755
--- a/buseir
+++ b/buseir
@@ -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
5SITE=https://buseireann.ie 5SITE="https://buseireann.ie"
6CACHE=$XDG_CACHE_HOME/buseir 6CACHE="$XDG_CACHE_HOME/buseir"
7TMP=/tmp/buseir 7TMP="/tmp/buseir"
8 8
9menu() { fzf -m --reverse --height=12; } 9menu() { 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
20sync() { 20sync() {
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
37stops() { 36stops() {
@@ -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
45printStop() { 44printStop() {