openvolga/when_my_bus.sh

21 lines
1.1 KiB
Bash
Raw Permalink Normal View History

2024-12-30 23:27:30 +00:00
#!/bin/bash
selected_station=$(cat stations.json | jq -r '.[] | "\(.station_id | tostring) \(.name) - \(.address)"' | fzf --bind 'enter:become(echo {1})')
fetch_buses_from_station() {
echo "Nearest buses from station $1:"
2024-12-31 08:55:21 +00:00
cat stations.json | jq -r --arg id $1 'map(select(.station_id == ($id | tonumber))) | .[0] | "https://www.openstreetmap.org/?mlat=\(.lat)&mlon=\(.lng)#map=18/\(.lat)/\(.lng)\ngeo:\(.lat),\(.lng)?z=18"'
2024-12-31 19:00:17 +00:00
curl -s -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:127.0) Gecko/20100101 Firefox/127.0' --compressed "https://api.merlin.tvercard.ru/api/client/v1/stations/$1/schedules/nearest?nearest_vehicle_amount=3" | jq -r '.[] | "\(.vehicle_arrival_time[].arrival_time) \(.vehicle_arrival_time[].arrival_time_comment) <- \(.route.name) \(.route.comment)"' | sort | uniq | awk -F' ' '{
cmd = "date -d " $1 " +%s"
cmd | getline future_time
close(cmd)
cmd = "date +%s"
cmd | getline current_time
close(cmd)
diff = (future_time - current_time) / 60
printf "%s min " "%s %s %s\n", diff, $2, $3, $4
}'
2024-12-30 23:27:30 +00:00
}
export -f fetch_buses_from_station
2024-12-31 06:57:06 +00:00
watch --interval 15 -x bash -c "fetch_buses_from_station $selected_station"