73 lines
2.4 KiB
Bash
73 lines
2.4 KiB
Bash
|
#!/bin/sh
|
||
|
|
||
|
icon="🚄"
|
||
|
path_pid="/tmp/polybar-network-wifionice.pid"
|
||
|
|
||
|
print_train_info() {
|
||
|
while true; do
|
||
|
if [ "$(iwgetid -r)" = "WIFIonICE" ] || [ "$(iwgetid -r)" = "WIFI@DB" ]; then
|
||
|
wifionice=$(curl -sLf https://iceportal.de/api1/rs/status)
|
||
|
|
||
|
if [ "$(echo "$wifionice" | jq .connection)" = "true" ]; then
|
||
|
wifionice_speed=$(echo "$wifionice" | jq .speed)
|
||
|
wifionice_conn=$( echo "$wifionice" | jq -r .connectivity.currentState )
|
||
|
wifionice_nextConn=$( echo "$wifionice" | jq -r .connectivity.nextState )
|
||
|
wifionice_connTime=$( echo "$wifionice" | jq -r .connectivity.remainingTimeSeconds | awk '{printf "%d m", $1/60}' )
|
||
|
if [ "$wifionice_speed" -ne 0 ]; then
|
||
|
wifionice_speed=" - $wifionice_speed km/h"
|
||
|
else
|
||
|
wifionice_speed=""
|
||
|
fi
|
||
|
|
||
|
station=$(curl -sLf https://iceportal.de/api1/rs/tripInfo/trip | jq '[.[].stops[]? | select(.info.passed == false)][0]')
|
||
|
|
||
|
station_name=$(echo "$station" | jq -r '.station.name')
|
||
|
|
||
|
station_track=$(echo "$station" | jq -r '.track.actual')
|
||
|
|
||
|
station_arrival=$(echo "$station" | jq -r '.timetable.scheduledArrivalTime')
|
||
|
station_arrival=$(date --date="@$((station_arrival / 1000))" +%H:%M)
|
||
|
|
||
|
station_delay=$(echo "$station" | jq -r '.timetable.arrivalDelay')
|
||
|
if [ -n "$station_delay" ]; then
|
||
|
station_delay=" ($station_delay)"
|
||
|
else
|
||
|
station_delay=""
|
||
|
fi
|
||
|
|
||
|
if [ "${wifionice_conn}" = "NO_INFO" ]; then
|
||
|
net_text="Net: 🤷"
|
||
|
else
|
||
|
net_text="Net: $wifionice_conn → $wifionice_nextConn ($wifionice_connTime)"
|
||
|
fi
|
||
|
|
||
|
echo "$icon $station_arrival$station_delay - $station_name, Gl. $station_track$wifionice_speed | $net_text"
|
||
|
fi
|
||
|
sleep 10
|
||
|
else
|
||
|
echo "" # hidden
|
||
|
sleep 600 &
|
||
|
wait
|
||
|
fi
|
||
|
done
|
||
|
}
|
||
|
|
||
|
network_update() {
|
||
|
pid=$(cat "$path_pid")
|
||
|
if [ "$pid" != "" ]; then
|
||
|
kill -USR1 "$pid"
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
case "$1" in
|
||
|
--update)
|
||
|
network_update
|
||
|
;;
|
||
|
*)
|
||
|
echo $$ > $path_pid
|
||
|
trap exit INT
|
||
|
trap "echo" USR1
|
||
|
print_train_info # Does not return
|
||
|
;;
|
||
|
esac
|