Added ICE polybar module

This commit is contained in:
marc
2023-11-21 13:53:13 +01:00
parent ad76fdf575
commit f95a9948a6
4 changed files with 46 additions and 1 deletions

View File

@@ -51,4 +51,4 @@ bottom = false
modules-left = spotify modules-left = spotify
modules-center = date modules-center = date
modules-right = i3-mode modules-right = ice i3-mode

View File

@@ -55,3 +55,7 @@ fg = ${colour-scheme.base0C}
[colours/spotify] [colours/spotify]
bg = ${colour-scheme.base00} bg = ${colour-scheme.base00}
fg = ${colour-scheme.base0A} fg = ${colour-scheme.base0A}
[colours/ice]
bg = ${colour-scheme.base00}
fg = ${colour-scheme.base0A}

View File

@@ -0,0 +1,8 @@
[module/ice]
type = custom/script
exec = ~/.config/polybar/scripts/ice.sh
interval = 5
format-background = ${colours/ice.bg}
format-foreground = ${colours/ice.fg}
format-padding = 1

33
config/polybar/scripts/ice.sh Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/sh
# Show current train speed on ICE
main() {
status=$(curl -X GET https://iceportal.de/api1/rs/status 2>/dev/null)
tripInfo=$(curl -X GET https://iceportal.de/api1/rs/tripInfo/trip 2>/dev/null)
if [[ -z $status || -z $tripInfo ]]; then
return
fi
# Speed
speed=$(echo $status | jq ".speed")
# Next stop
nextId=$(echo $tripInfo | jq ".trip.stopInfo.actualNext")
nextStop=$(echo $tripInfo | jq ".trip.stops[] | select( .station.evaNr == $nextId )")
nextStopName=$(echo $nextStop | jq -r ".station.name")
nextStopArrival=$(echo $nextStop | jq ".timetable.actualArrivalTime")
nextStopRemainingSeconds=$(expr $(expr $nextStopArrival / 1000) - $(date +%s))
if [[ ${nextStopRemainingSeconds:0:1} == "-" ]]; then
nextStopRemainingTime="Arribada!"
else
nextStopRemainingTime=$(date -d@$nextStopRemainingSeconds -u +%Hh%Mm%Ss)
fi
echo "$nextStopName ·  $nextStopRemainingTime · 󰓅 $speed km/h"
}
main "$@"