From a930b7ec6463d6ef7ade7ba12026fe8328d3c7dd Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Mon, 9 Jan 2017 20:17:01 +0100 Subject: Switch to python3 and some other cleanups --- HACKING | 2 +- README | 2 +- examples/trip-query.py | 13 +++++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/HACKING b/HACKING index cd08e95..94b27ae 100644 --- a/HACKING +++ b/HACKING @@ -12,7 +12,7 @@ To run a single test in more detail use e.g. You can use the LPF_DEBUG variable to make libplanfahr write out the querry results. E.g. - LPF_DEBUG=provider ./run python examples/trip-query.py Gelsenkirchen Essen + LPF_DEBUG=provider ./run python3 examples/trip-query.py Gelsenkirchen Essen will put all queries to ~/.cache/libplanfahr//. diff --git a/README b/README index 19eedef..e54b001 100644 --- a/README +++ b/README @@ -26,6 +26,6 @@ To run from the compiled source code use for example - ./run python examples/trip-query.py Gelsenkirchen Essen + ./run python3 examples/trip-query.py Gelsenkirchen Essen If you want to contribute to libplanfahr see the HACKING document. diff --git a/examples/trip-query.py b/examples/trip-query.py index 74ccc04..1c814d5 100644 --- a/examples/trip-query.py +++ b/examples/trip-query.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # vim: set fileencoding=utf-8 : # # Query trips between the two locations given on the command line @@ -35,6 +35,7 @@ end = None provider = None options = None + def quit(error=None): if error: print("Error: %s" % error) @@ -59,13 +60,14 @@ def locs_cb(locs, userdata, err): dt = GLib.DateTime.new_local(*userdata) if userdata else GLib.DateTime.new_now_local() provider.get_trips(start, end, dt, 0, trips_cb, None) + def format_full(trips): i = 0 for trip in trips: i += 1 j = 0 msg = ' - CANCELED' if trip.props.status == Lpf.TripStatusFlags.CANCELED else '' - print ('Trip #%d%s' % (i, msg)) + print('Trip #%d%s' % (i, msg)) for part in trip.props.parts: j += 1 print(' Part #%d' % j) @@ -91,12 +93,13 @@ def format_full(trips): print(" Stops: 0") print("") + def format_terse(trips): i = 0 for trip in trips: i += 1 msg = ' - CANCELED' if trip.props.status == Lpf.TripStatusFlags.CANCELED else '' - print ('Trip #%d%s' % (i, msg)) + print('Trip #%d%s' % (i, msg)) start = trip.props.parts[0].props.start end = trip.props.parts[-1].props.end print(" Start: %s" % start.props.name) @@ -122,6 +125,7 @@ def trips_cb(trips, userdata, err): format_terse(trips) quit() + def parse_datetime(when): if not when: return None @@ -131,6 +135,7 @@ def parse_datetime(when): H, M = time.split(':') return tuple(map(int, [y, m, d, H, M, '00'])) + def main(argv): global mainloop, provider, options @@ -162,6 +167,6 @@ def main(argv): mainloop.run() return 0 + if __name__ == "__main__": sys.exit(main(sys.argv)) - -- cgit v1.2.3