Initial Commit
authorCian Bagshaw <cian@cianb.xyz>
Tue, 28 Feb 2023 00:03:14 +0000 (00:03 +0000)
committerCian Bagshaw <cian@cianb.xyz>
Tue, 28 Feb 2023 00:03:14 +0000 (00:03 +0000)
Provides for download, cache, search, and display of bus stop data.

buseir [new file with mode: 0755]

diff --git a/buseir b/buseir
new file mode 100755 (executable)
index 0000000..36a5d12
--- /dev/null
+++ b/buseir
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+SITE=https://buseireann.ie
+CACHE=$XDG_CACHE_HOME/buseir
+TMP=/tmp/buseir
+MAP=http://www.google.com/maps/place
+
+sync() {
+       echo Syncing data...
+       [ ! -d $TMP ] && mkdir -p $TMP
+       wget "$SITE/inc/proto/bus_stop_points.php" -qO $TMP/busp \
+               || (echo Connection failed! && exit);
+       head -c -1 $TMP/busp | tail -c +27 | jq -r '.bus_stops|.[]|.[]' \
+               | paste -d "," - - - - - > "$CACHE"/stops.csv;
+}
+
+stopInfo() {
+       [ "$1" == "search" ] && STOP=$(stopInfo | fzf) || STOP=$1
+       [ -z "$2" ] && COL=2 \
+               || case $2 in
+                       duid) COL=1;; name) COL=2;; lat) COL=3;; long) COL=4;;
+                       num) COL=5;; pos) COL=3-4;; all) COL=1-5;;
+                       map) xdg-open $MAP/$(stopInfo "$STOP" "pos"); exit;;
+               esac 
+       grep "$STOP" $CACHE/stops.csv | cut -d, -f$COL
+}
+
+[ ! -d $CACHE ] && mkdir -p "$CACHE" && sync
+
+case $1 in
+       sync) sync;;
+       stop) stopInfo $2 $3;;
+esac