aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGuido G√ľnther <agx@sigxcpu.org>2014-03-06 19:20:11 +0100
committerGuido G√ľnther <agx@sigxcpu.org>2014-03-06 19:21:57 +0100
commit131a61abc715ce90df157d9a3d6019e43ea798a2 (patch)
treed0f0024cfc35818905230340bdd1b22aad4405a5 /examples
parent6f55eb2e80f4948ad841d292c9f81c11620abcc6 (diff)
trip-query.py: Use a terse format by default
Diffstat (limited to 'examples')
-rw-r--r--examples/trip-query.py43
1 files changed, 34 insertions, 9 deletions
diff --git a/examples/trip-query.py b/examples/trip-query.py
index d8ad4aa..10c4616 100644
--- a/examples/trip-query.py
+++ b/examples/trip-query.py
@@ -14,6 +14,7 @@ mainloop = None
start = None
end = None
provider = None
+options = None
def quit(error=None):
if error:
@@ -38,14 +39,7 @@ def locs_cb(locs, userdata, err):
now = GLib.DateTime.new_now_local()
provider.get_trips(start, end, now, 0, trips_cb, None)
-
-def trips_cb(trips, userdata, err):
- if err:
- quit(err.message)
- return
-
- if not trips:
- raise Exception("Failed to find any trips")
+def format_full(trips):
i = 0
for trip in trips:
i += 1
@@ -73,14 +67,45 @@ def trips_cb(trips, userdata, err):
else:
print(" Stops: 0")
print("")
+
+def format_terse(trips):
+ i = 0
+ for trip in trips:
+ i += 1
+ print ('Trip #%d' % i)
+ start = trip.props.parts[0].props.start
+ end = trip.props.parts[-1].props.end
+ print(" Start: %s" % start.props.name)
+ print(" Departure: %s" % start.props.departure.format("%F %H:%M"))
+ print(" Delay: %s" % start.props.departure_delay)
+ print(" End: %s" % end.props.name)
+ 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("")
+
+
+def trips_cb(trips, userdata, err):
+ if err:
+ quit(err.message)
+ return
+
+ if not trips:
+ raise Exception("Failed to find any trips")
+ if options.format == 'full':
+ format_full(trips)
+ else:
+ format_terse(trips)
quit()
def main(argv):
- global mainloop, provider
+ global mainloop, provider, options
parser = optparse.OptionParser()
parser.add_option("--provider", "-p", dest="provider",
help="Provider to use", default="de-db")
+ parser.add_option("--format", dest="format",
+ help="Format to use (terse or full)", default="terse")
options, args = parser.parse_args(argv)
if len(args) == 3: