From d2e4f433c1156a4ba4cb6d260440bfb5280f5a20 Mon Sep 17 00:00:00 2001 From: Cian Bagshaw Date: Sun, 7 May 2023 13:08:46 +0100 Subject: [PATCH] Sync bus routes --- buseir | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/buseir b/buseir index f416f8b..fa441b5 100755 --- 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 } -- 2.20.1