import sqlalchemy.types
from .db import connect, metadata, tables as tables_module
+from pokedex.lookup import lookup as pokedex_lookup
def main():
if len(sys.argv) <= 1:
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
else:
print 'loaded'
-def csvexport(engine_uri, directory='.'):
+def command_csvexport(engine_uri, directory='.'):
import csv
session = connect(engine_uri)
writer.writerow(csvs)
+def command_lookup(engine_uri, name):
+ # XXX don't require uri! somehow
+ session = connect(engine_uri)
+
+ 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.
+ lookup {uri} [name] Look up something in the Pokédex.
These commands are only useful for developers:
csvimport {uri} [dir] Import data from a set of CSVs to the database