X-Git-Url: http://git.veekun.com/zzz-pokedex.git/blobdiff_plain/91df48e83cec5ac8a8cdcf1b2b1961420d579d6b..b08b064e9f013e8233b207360d68305a6b9652f2:/pokedex/__init__.py diff --git a/pokedex/__init__.py b/pokedex/__init__.py index 3908d8d..6954149 100644 --- a/pokedex/__init__.py +++ b/pokedex/__init__.py @@ -15,14 +15,14 @@ def main(): args = sys.argv[2:] # Find the command as a function in this file - func = globals().get(command, None) - if func and callable(func) and command != 'main': + func = globals().get("command_%s" % command, None) + if func: func(*args) else: - help() + command_help() -def csvimport(engine_uri, directory='.'): +def command_csvimport(engine_uri, directory='.'): import csv from sqlalchemy.orm.attributes import instrumentation_registry @@ -129,7 +129,7 @@ def csvimport(engine_uri, directory='.'): else: print 'loaded' -def csvexport(engine_uri, directory='.'): +def command_csvexport(engine_uri, directory='.'): import csv session = connect(engine_uri) @@ -160,17 +160,21 @@ def csvexport(engine_uri, directory='.'): writer.writerow(csvs) -def lookup(engine_uri, name): +def command_lookup(engine_uri, name): # XXX don't require uri! somehow session = connect(engine_uri) - results = pokedex_lookup(session, name) - print "Matched:" - for object, matchiness in results: - print object.__tablename__, object.name, "(%.03f)" % matchiness + results, exact = pokedex_lookup(session, name) + if exact: + print "Matched:" + else: + print "Fuzzy-matched:" + + for object in results: + print object.__tablename__, object.name -def help(): +def command_help(): print u"""pokedex -- a command-line Pokédex interface help Displays this message.