Last active
March 17, 2020 12:41
-
-
Save andys8/86cbc65ed90d1f9c6aaab83ff34c2862 to your computer and use it in GitHub Desktop.
mvg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Request of <https://www.mvg.de/dienste/verbindungen.html> | |
set -eu pipefail | |
url="https://www.mvg.de/api/fahrinfo/routing/?fromStation=de:09162:2&toStation=de:09179:6180&transportTypeBus=false&transportTypeUnderground=false&transportTypeBoat=false&transportTypeTram=false&transportTypeCable=false&changeLimit=0&sapTickets=true" | |
json=$(curl -s "$url" || '') | |
if [[ $json == "" ]]; then | |
echo "$(tput setaf 3)Failed$(tput sgr 0)" | |
exit 1 | |
fi | |
toDate="ts => new Date(ts)" | |
toTime="d => d.getHours() + ':' + d.getMinutes()" | |
departure=$(echo "$json" | fx ".connectionList[0].departure" "$toDate" "$toTime") | |
echo "$(tput setaf 2)$departure$(tput setaf 8) (departure)$(tput sgr 0)" | |
# Delay | |
delay=$(echo "$json" | fx ".connectionList[0].connectionPartList[0].delay") | |
delayMin="+${delay} min" | |
if [[ $delay != "0" ]]; then | |
echo "$(tput setaf 3)$delayMin$(tput sgr 0)" | |
fi | |
# Notifications | |
toText="(ns = []) => ns.map(n => n.title + ': ' + n.description).join('\n\n')" | |
notifcations=$(echo "$json" | fx ".connectionList[0].connectionPartList[0].notifications" "$toText") | |
if [[ $notifcations != "" ]]; then | |
echo "$(tput setaf 9)$notifcations$(tput sgr 0)" | |
fi | |
# Desktop notification | |
notify-send "$departure" "$delayMin" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment