Skip to content

Instantly share code, notes, and snippets.

@crater2150
Created August 26, 2019 18:24
Show Gist options
  • Save crater2150/dd2f2a51ffdb9f548548a7c24c47895d to your computer and use it in GitHub Desktop.
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
#!/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