|
|
|
@ -25,6 +25,7 @@ class PokemonList:
|
|
|
|
|
result = session.query(Pokemon).where(Pokemon.end_time > datetime.now() + self.timedelta)\
|
|
|
|
|
.order_by(Pokemon.name)
|
|
|
|
|
session.commit()
|
|
|
|
|
session.close()
|
|
|
|
|
return result.all()
|
|
|
|
|
|
|
|
|
|
def sort_by_cp(self, reverse=False):
|
|
|
|
@ -36,6 +37,7 @@ class PokemonList:
|
|
|
|
|
result = session.query(Pokemon).where(Pokemon.end_time > datetime.now() + self.timedelta) \
|
|
|
|
|
.order_by(Pokemon.cp)
|
|
|
|
|
session.commit()
|
|
|
|
|
session.close()
|
|
|
|
|
return result.all()
|
|
|
|
|
|
|
|
|
|
def sort_by_level(self, reverse=False):
|
|
|
|
@ -47,18 +49,21 @@ class PokemonList:
|
|
|
|
|
result = session.query(Pokemon).where(Pokemon.end_time > datetime.now() + self.timedelta) \
|
|
|
|
|
.order_by(Pokemon.level)
|
|
|
|
|
session.commit()
|
|
|
|
|
session.close()
|
|
|
|
|
return result.all()
|
|
|
|
|
|
|
|
|
|
def sort_by_distance(self, location: Location, reverse=False):
|
|
|
|
|
with Session(self.engine) as session:
|
|
|
|
|
result = session.query(Pokemon).where(Pokemon.end_time > datetime.now() + self.timedelta)
|
|
|
|
|
session.commit()
|
|
|
|
|
session.close()
|
|
|
|
|
return sorted(result.all(), key=lambda pokemon: location.distance(pokemon.location), reverse=reverse)
|
|
|
|
|
|
|
|
|
|
def search_by_name(self, query: str):
|
|
|
|
|
with Session(self.engine) as session:
|
|
|
|
|
result = session.query(Pokemon).where(Pokemon.end_time > datetime.now() + self.timedelta)
|
|
|
|
|
session.commit()
|
|
|
|
|
session.close()
|
|
|
|
|
return list(filter(lambda pokemon: partial_ratio(query.lower(), pokemon.name) >= 80, result.all()))
|
|
|
|
|
|
|
|
|
|
def insert_to_database(self, pokemons: List[Pokemon]):
|
|
|
|
@ -66,4 +71,5 @@ class PokemonList:
|
|
|
|
|
with Session(self.engine) as session:
|
|
|
|
|
session.add_all(pokemons)
|
|
|
|
|
session.commit()
|
|
|
|
|
session.close()
|
|
|
|
|
|
|
|
|
|