forked from kunsi/dotfiles
ice-status.py: more improvements
This commit is contained in:
parent
e920bf8281
commit
24c0b05cf4
1 changed files with 16 additions and 6 deletions
|
@ -7,13 +7,17 @@ from sys import exit
|
|||
|
||||
|
||||
# bundlewrap.utils.text.format_duration, but trimmed down
|
||||
def format_time(seconds):
|
||||
def format_time(seconds, with_seconds=True):
|
||||
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 seconds > 0 or not components:
|
||||
if (seconds > 0 and with_seconds) or not components:
|
||||
components.append('{}s'.format(seconds))
|
||||
return " ".join(components)
|
||||
|
||||
|
@ -27,6 +31,8 @@ try:
|
|||
):
|
||||
exit(0)
|
||||
|
||||
now = datetime.now()
|
||||
|
||||
trip_info_req = get('https://portal.imice.de/api1/rs/tripInfo/trip')
|
||||
trip_info_req.raise_for_status()
|
||||
trip_info = trip_info_req.json()['trip']
|
||||
|
@ -39,21 +45,25 @@ try:
|
|||
for stop in trip_info['stops']:
|
||||
if stop['station']['evaNr'] == next_stop_id:
|
||||
if stop['timetable']['departureDelay']:
|
||||
delay = ' ({})'.format(stop['timetable']['departureDelay'])
|
||||
delay = ' | <span color="#FF0000">{}</span>'.format(stop['timetable']['departureDelay'])
|
||||
else:
|
||||
delay = ''
|
||||
|
||||
next_stop = '{} [{}] {}{}'.format(
|
||||
arrival = datetime.fromtimestamp(stop['timetable']['actualArrivalTime']/1000)
|
||||
arrival_in = arrival - now
|
||||
|
||||
next_stop = '{} <span color="#999999">[{}]</span> {} ({}{})'.format(
|
||||
stop['station']['name'],
|
||||
stop['track']['actual'],
|
||||
datetime.fromtimestamp(stop['timetable']['actualArrivalTime']/1000).strftime('%H:%M'),
|
||||
arrival.strftime('%H:%M'),
|
||||
format_time(arrival_in.total_seconds(), False),
|
||||
delay
|
||||
)
|
||||
break
|
||||
else:
|
||||
next_stop = 'Endstation, bitte Aussteigen'
|
||||
|
||||
print('{}km/h > {} (Net: {} > [{}] {})'.format(
|
||||
print('<span color="#999999">{}km/h</span> > {} <span color="#999999">(Net: {} > [{}] {})</span>'.format(
|
||||
ice_status['speed'],
|
||||
next_stop,
|
||||
ice_status['connectivity']['currentState'],
|
||||
|
|
Loading…
Reference in a new issue