From 962708cb8f072892a3842b13b7f08f3c7b25bbbe Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Sat, 18 Feb 2017 17:39:57 +0100 Subject: trip-query: print overall trip duration --- examples/trip-query.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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("") -- cgit v1.2.3