i3pystatus uses native wifionice module now
This commit is contained in:
parent
910d8b91d0
commit
391bc96f7d
3 changed files with 5 additions and 121 deletions
|
@ -86,18 +86,17 @@ status.register("shell",
|
||||||
on_leftclick="xinput enable 'SynPS/2 Synaptics TouchPad'",
|
on_leftclick="xinput enable 'SynPS/2 Synaptics TouchPad'",
|
||||||
on_rightclick="xinput disable 'SynPS/2 Synaptics TouchPad'")
|
on_rightclick="xinput disable 'SynPS/2 Synaptics TouchPad'")
|
||||||
|
|
||||||
status.register("wifionice", wifi_adapters=['wlp3s0'])
|
#status.register("wifionice", wifi_adapters=['wlp3s0'])
|
||||||
status.register("wifionice",
|
status.register("wifionice",
|
||||||
hints = {"markup": "pango"},
|
hints = {"markup": "pango"},
|
||||||
travelynx_url='travelynx.franzi.business',
|
travelynx_url='travelynx.franzi.business',
|
||||||
wifi_adapters=['wlp3s0'],
|
wifi_adapters=['wlp3s0'],
|
||||||
format_offtrain='Wann wieder Zug?',
|
format_offtrain='Wann wieder Zug?',
|
||||||
format_ontrain='<span color="#999999">{speed}km/h</span> > {next_station}[ '
|
format_ontrain='[<span color="#999999">{speed}km/h</span> ]> {next_station}[ '
|
||||||
'<span color="#999999">\[{next_platform}\]</span> {arrival_time} '
|
'<span color="#999999">\[{next_platform}\]</span> {arrival_time} '
|
||||||
'({arrival_in}[ | <span color="#FF0000">{delay_minutes}</span>])][ '
|
'({arrival_in}[ | <span color="#FF0000">{delay}</span>])][ '
|
||||||
'<span color="#999999">(Net: {net_current} > [{net_duration}] '
|
'<span color="#999999">(Net: {net_current} > \[{net_duration}\] '
|
||||||
'{net_expected})</span>]',
|
'{net_expected})</span>]')
|
||||||
log_level='DEBUG')
|
|
||||||
#status.register("shell",
|
#status.register("shell",
|
||||||
# format="{output}",
|
# format="{output}",
|
||||||
# hints = {"markup": "pango"},
|
# hints = {"markup": "pango"},
|
||||||
|
|
|
@ -1,113 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
|
||||||
from requests import get
|
|
||||||
from subprocess import check_output
|
|
||||||
from sys import argv, exit
|
|
||||||
|
|
||||||
LINK_MODE = False
|
|
||||||
if len(argv) > 1 and argv[1] == '--link':
|
|
||||||
LINK_MODE = True
|
|
||||||
if len(argv) > 2:
|
|
||||||
LINK_TARGET = argv[2]
|
|
||||||
else:
|
|
||||||
LINK_TARGET = 'travelynx.franzi.business'
|
|
||||||
|
|
||||||
|
|
||||||
# bundlewrap.utils.text.format_duration, but trimmed down
|
|
||||||
def format_time(seconds):
|
|
||||||
if seconds is None:
|
|
||||||
return "?"
|
|
||||||
seconds = int(seconds)
|
|
||||||
components = []
|
|
||||||
if seconds >= 3600:
|
|
||||||
hours = int(seconds / 3600)
|
|
||||||
seconds -= hours * 3600
|
|
||||||
components.append('{}h'.format(hours))
|
|
||||||
if seconds >= 60:
|
|
||||||
minutes = int(seconds / 60)
|
|
||||||
seconds -= minutes * 60
|
|
||||||
components.append('{}m'.format(minutes))
|
|
||||||
if not components:
|
|
||||||
components.append('now')
|
|
||||||
return " ".join(components)
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
wifi_ssid = check_output("iw dev wlp3s0 link | awk '/SSID/ {print $2}'", shell=True).decode().strip().lower()
|
|
||||||
|
|
||||||
if wifi_ssid not in (
|
|
||||||
'wifi@db',
|
|
||||||
'wifionice'
|
|
||||||
):
|
|
||||||
exit(0)
|
|
||||||
|
|
||||||
now = datetime.now()
|
|
||||||
|
|
||||||
trip_info_req = get('https://iceportal.de/api1/rs/tripInfo/trip')
|
|
||||||
trip_info_req.raise_for_status()
|
|
||||||
trip_info = trip_info_req.json()['trip']
|
|
||||||
|
|
||||||
ice_status_req = get('https://iceportal.de/api1/rs/status')
|
|
||||||
ice_status_req.raise_for_status()
|
|
||||||
ice_status = ice_status_req.json()
|
|
||||||
|
|
||||||
if LINK_MODE:
|
|
||||||
check_output(['xdg-open', 'https://{}/s/{}?train={}%20{}'.format(
|
|
||||||
LINK_TARGET,
|
|
||||||
trip_info['stopInfo']['actualLast'],
|
|
||||||
trip_info['trainType'],
|
|
||||||
trip_info['vzn'],
|
|
||||||
)])
|
|
||||||
exit(0)
|
|
||||||
|
|
||||||
next_stop_id = trip_info['stopInfo']['actualNext']
|
|
||||||
for stop in trip_info['stops']:
|
|
||||||
if stop['station']['evaNr'] == next_stop_id:
|
|
||||||
|
|
||||||
if stop['timetable']['departureDelay']:
|
|
||||||
delay = ' | <span color="#FF0000">{}</span>'.format(stop['timetable']['departureDelay'])
|
|
||||||
else:
|
|
||||||
delay = ''
|
|
||||||
|
|
||||||
if stop['timetable'].get('actualArrivalTime', 0):
|
|
||||||
arrival = datetime.fromtimestamp(stop['timetable']['actualArrivalTime']/1000)
|
|
||||||
arrival_in = arrival - now
|
|
||||||
elif stop['timetable'].get('scheduledArrivalTime', 0):
|
|
||||||
arrival = datetime.fromtimestamp(stop['timetable']['scheduledArrivalTime']/1000)
|
|
||||||
arrival_in = arrival - now
|
|
||||||
else:
|
|
||||||
arrival = datetime.now()
|
|
||||||
arrival_in = timedelta()
|
|
||||||
|
|
||||||
next_stop = '{} <span color="#999999">[{}]</span> {} ({}{})'.format(
|
|
||||||
stop['station']['name'],
|
|
||||||
stop['track']['actual'],
|
|
||||||
arrival.strftime('%H:%M'),
|
|
||||||
format_time(arrival_in.total_seconds()),
|
|
||||||
delay
|
|
||||||
)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
next_stop = 'Endstation, bitte Aussteigen'
|
|
||||||
|
|
||||||
net_current = ice_status['connectivity']['currentState']
|
|
||||||
net_future = ice_status['connectivity']['nextState']
|
|
||||||
|
|
||||||
if net_current not in (None, 'NO_INFO') or net_future not in (None, 'NO_INFO'):
|
|
||||||
net = ' <span color="#999999">(Net: {} > [{}] {})</span>'.format(
|
|
||||||
net_current,
|
|
||||||
format_time(ice_status['connectivity']['remainingTimeSeconds']),
|
|
||||||
net_future,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
net = ''
|
|
||||||
|
|
||||||
print('<span color="#999999">{}km/h</span> > {}{}'.format(
|
|
||||||
ice_status['speed'],
|
|
||||||
next_stop,
|
|
||||||
net,
|
|
||||||
))
|
|
||||||
except Exception as e:
|
|
||||||
print(repr(e))
|
|
||||||
exit(0)
|
|
|
@ -5,8 +5,6 @@ OUT="$(xset q | grep timeout | awk '{print $2}')"
|
||||||
if [ "$OUT" = "0" ]
|
if [ "$OUT" = "0" ]
|
||||||
then
|
then
|
||||||
echo "OFF"
|
echo "OFF"
|
||||||
exit 1
|
|
||||||
else
|
else
|
||||||
echo "${OUT}s"
|
echo "${OUT}s"
|
||||||
exit 0
|
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue