diff options
author | Guido Günther <agx@sigxcpu.org> | 2017-02-18 17:39:57 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2017-02-18 17:40:59 +0100 |
commit | 962708cb8f072892a3842b13b7f08f3c7b25bbbe (patch) | |
tree | d451f3d33555dd8d3a0a689d9b174aef4ba3e7d2 /examples | |
parent | 3aeeb059230fc068b69217b4a7af0d80d23528a0 (diff) |
trip-query: print overall trip duration
Diffstat (limited to 'examples')
-rw-r--r-- | examples/trip-query.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/examples/trip-query.py b/examples/trip-query.py index 10c9648..c3d541f 100644 --- a/examples/trip-query.py +++ b/examples/trip-query.py @@ -35,6 +35,8 @@ start = None end = None provider = None options = None +G_TIME_SPAN_HOUR = 3600000000 +G_TIME_SPAN_MINUTE = 60000000 def quit(error=None): @@ -62,6 +64,17 @@ def locs_cb(locs, userdata, err): provider.get_trips(start, end, dt, 0, trips_cb, None) +def duration(trip): + start = trip.props.parts[0].props.start + end = trip.props.parts[-1].props.end + duration = GLib.DateTime.difference( + end.props.arrival, + start.props.departure) + hours = duration / G_TIME_SPAN_HOUR + minutes = (duration % G_TIME_SPAN_HOUR) / G_TIME_SPAN_MINUTE + return (hours, minutes) + + def format_full(trips): i = 0 for trip in trips: @@ -92,6 +105,7 @@ def format_full(trips): ", ".join([s.props.name for s in part.props.stops]))) else: print(" Stops: 0") + print(' Duration: %.2d:%.2d' % duration(trip)) print("") @@ -110,6 +124,7 @@ def format_terse(trips): print(" Arrival: %s" % end.props.arrival.format("%F %H:%M")) print(" Delay: %s" % end.props.arrival_delay) print(" Switches: %d" % (len(trip.props.parts)-1)) + print(' Duration: %.2d:%.2d' % duration(trip)) print("") |