aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGuido G√ľnther <agx@sigxcpu.org>2014-03-05 16:07:53 +0100
committerGuido G√ľnther <agx@sigxcpu.org>2014-03-05 16:38:53 +0100
commit20470d4e5ce19ca273ed4640622627a8fbdeef07 (patch)
treecccc271ee84dbc333cd64ae39906d687fe63716e /examples
parent734335998b3443ea86e3f565cc12295b12b6106d (diff)
example.py: Allow to switch providers easily
Diffstat (limited to 'examples')
-rw-r--r--examples/trip-query.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/examples/trip-query.py b/examples/trip-query.py
index 54b552f..d8ad4aa 100644
--- a/examples/trip-query.py
+++ b/examples/trip-query.py
@@ -4,6 +4,7 @@
# given on the command line
import sys
+import optparse
from gi.repository import Lpf
from gi.repository import GObject
@@ -67,25 +68,30 @@ def trips_cb(trips, userdata, err):
print(" Line: %s" % part.props.line)
print(" Delay: %s" % end.props.arrival_delay)
if part.props.stops and len(part.props.stops) > 0:
- print " %s Stops: %s" % (len(part.props.stops),
- ", ".join([s.props.name for s in part.props.stops]))
+ print(" %s Stops: %s" % (len(part.props.stops),
+ ", ".join([s.props.name for s in part.props.stops])))
else:
- print " Stops: 0"
+ print(" Stops: 0")
print("")
quit()
-def main(args):
+def main(argv):
global mainloop, provider
+ parser = optparse.OptionParser()
+ parser.add_option("--provider", "-p", dest="provider",
+ help="Provider to use", default="de-db")
+ options, args = parser.parse_args(argv)
+
if len(args) == 3:
start = args[1]
end = args[2]
else:
- print("Usage: %s <from> <to>" % args[0])
+ print("Usage: %s <from> <to>" % argv[0])
return 1
manager = Lpf.Manager()
- provider = manager.activate_provider("de-db")
+ provider = manager.activate_provider(options.provider)
print("Loaded provider %s" % provider.props.name)
provider.get_locs(start, locs_cb, end)