Sync bus routes
authorCian Bagshaw <cian@cianb.xyz>
Sun, 7 May 2023 12:08:46 +0000 (13:08 +0100)
committerCian Bagshaw <cian@cianb.xyz>
Sun, 7 May 2023 12:08:46 +0000 (13:08 +0100)
buseir

diff --git a/buseir b/buseir
index f416f8b..fa441b5 100755 (executable)
--- a/buseir
+++ b/buseir
@@ -9,9 +9,17 @@ MENU="fzf --reverse --height=12"
 sync() {
        echo Syncing data...
        [ ! -d $TMP ] && mkdir -p $TMP
-       wget "$SITE/inc/proto/bus_stop_points.php" -qO $TMP/stops \
+       rm -f $TMP/*
+       wget -qP $TMP "$SITE" "$SITE/inc/proto/bus_stop_points.php" \
                || (echo Connection failed! && exit);
-       grep -o "{.*}" $TMP/stops | jq -r '.bus_stops[][]' \
+       xmllint --html --xpath \
+               "//select[@id='form-fare-finder-service']/option/text()" $TMP/index.html 2>/dev/null \
+               | sed 's/\s*:\s*/,/; /Select Service/d' > $TMP/routes.csv
+       for i in $(cut -d, -f1 $TMP/routes.csv); \
+               do echo "$SITE/inc/proto/fareDestinations.php?fare=$i"; done \
+               | wget -q -i - -O - | jq -r '[.fareDestinations[]|.name]|@csv' \
+               | paste -d, $TMP/routes.csv - > $CACHE/routes.csv
+       grep -o "{.*}" $TMP/bus_stop_points.php | jq -r '.bus_stops[][]' \
                | paste -d, - - - - - > $CACHE/stops.csv
 }