Created
August 26, 2019 18:24
-
-
Save crater2150/dd2f2a51ffdb9f548548a7c24c47895d to your computer and use it in GitHub Desktop.
Simple command line tool to show timetable of the ICE you're sitting in
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/zsh | |
tt_data=$(curl -s https://iceportal.de/api1/rs/tripInfo/trip) | |
if ! head -n 3 <<<"$tt_data" | grep -q '{'; then | |
echo "Invalid API response. Are you on the ICE Wifi?" | |
exit 1 | |
fi | |
tt_data=$( | |
jq '[.trip.stops[] | |
|{ | |
station: .station.name, | |
scheduled: .timetable.scheduledArrivalTime, | |
actual: .timetable.actualArrivalTime, | |
delay: .timetable.arrivalDelay | |
}]' <<<"$tt_data" | |
) | |
timetable() { | |
jq -r ' | |
def dbtime: . / 1000 | strflocaltime("%H:%M"); | |
.[]| .station + "\t" | |
+ (.scheduled | values | dbtime) | |
+ "\t" | |
+ (.actual | values | dbtime)' <<<"$tt_data" | \ | |
column --table --separator=$'\t' --table-columns=Bahnhof,Ankunft,tatsächlich |\ | |
awk "/${1:-^$}/"' {printf("\033[1;%dm%s\033[0m\n",33,$0);next} | |
{print}' | |
} | |
case $1 in | |
timetable|tt|*) timetable $2;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment