Stubbing out a lookup function. #15
[zzz-pokedex.git] / pokedex / lookup.py
1 # encoding: utf8
2 from sqlalchemy.sql import func
3
4 import pokedex.db.tables as tables
5
6 def lookup(session, name):
7 """Attempts to find some sort of object, given a database session and name.
8
9 Returns a list of (object, matchiness) tuples. Matchiness is 1 for exact
10 matches. It is possible to get multiple exact matches; for example,
11 'Metronome' will match both the move and the item. In these cases, the
12 results are returned in rough order of "importance", e.g., Pokémon come
13 before moves come before types.
14
15 This function does fuzzy matching iff there are no exact matches.
16
17 Formes are not returned; "Shaymin" will return only grass Shaymin.
18
19 Currently recognizes:
20 - Pokémon names: "Eevee"
21 """
22
23 q = session.query(tables.Pokemon) \
24 .filter(func.lower(tables.Pokemon.name) == name.lower()) \
25 .filter_by(forme_base_pokemon_id=None)
26
27 try:
28 result = q.one()
29 return [ (result, 1) ]
30 except:
31 return []