|
|
|
@ -1,11 +1,14 @@
|
|
|
|
|
from ispoof.objects.pokemon import Pokemon
|
|
|
|
|
from ispoof.core.location import Location
|
|
|
|
|
from ispoof.spoofer.location import Location
|
|
|
|
|
from thefuzz.fuzz import partial_ratio
|
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
|
from sqlalchemy.engine import Engine
|
|
|
|
|
from typing import List
|
|
|
|
|
from sqlalchemy import desc
|
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PokemonList:
|
|
|
|
@ -50,9 +53,6 @@ class PokemonList:
|
|
|
|
|
with Session(self.engine) as session:
|
|
|
|
|
result = session.query(Pokemon).where(Pokemon.end_time > datetime.now() + self.timedelta)
|
|
|
|
|
session.commit()
|
|
|
|
|
print(len(result.all()))
|
|
|
|
|
print(type(result.all()))
|
|
|
|
|
print(result.all().sort(key=lambda pokemon: location.distance(pokemon.location), reverse=reverse))
|
|
|
|
|
return sorted(result.all(), key=lambda pokemon: location.distance(pokemon.location), reverse=reverse)
|
|
|
|
|
|
|
|
|
|
def search_by_name(self, query: str):
|
|
|
|
@ -62,6 +62,7 @@ class PokemonList:
|
|
|
|
|
return list(filter(lambda pokemon: partial_ratio(query.lower(), pokemon.name) >= 80, result.all()))
|
|
|
|
|
|
|
|
|
|
def insert_to_database(self, pokemons: List[Pokemon]):
|
|
|
|
|
logger.info("Add pokemons to database.")
|
|
|
|
|
with Session(self.engine) as session:
|
|
|
|
|
session.add_all(pokemons)
|
|
|
|
|
session.commit()
|
|
|
|
|