Pokédex lookup now uses a whoosh index and spell-checker. #15
[zzz-pokedex.git] / pokedex / __init__.py
index 02b8ce5..89ad673 100644 (file)
@@ -5,6 +5,7 @@ from sqlalchemy.exc import IntegrityError
 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:
@@ -159,11 +160,25 @@ def csvexport(engine_uri, directory='.'):
 
             writer.writerow(csvs)
 
+def 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():
     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