diff --git a/ispoof/lists/pokemonlist.py b/ispoof/lists/pokemonlist.py index 7763182..0d21697 100644 --- a/ispoof/lists/pokemonlist.py +++ b/ispoof/lists/pokemonlist.py @@ -26,15 +26,31 @@ class PokemonList: return result.all() def sort_by_cp(self, reverse=False): - self.pokemons.sort(key=lambda pokemon: pokemon.cp, reverse=reverse) + with Session(self.engine) as session: + if reverse: + result = session.query(Pokemon).where(Pokemon.end_time > datetime.now() + self.timedelta) \ + .order_by(desc(Pokemon.cp)) + else: + result = session.query(Pokemon).where(Pokemon.end_time > datetime.now() + self.timedelta) \ + .order_by(Pokemon.cp) + session.commit() + return result.all() def sort_by_level(self, reverse=False): - self.pokemons.sort(key=lambda pokemon: pokemon.level, reverse=reverse) + with Session(self.engine) as session: + if reverse: + result = session.query(Pokemon).where(Pokemon.end_time > datetime.now() + self.timedelta) \ + .order_by(desc(Pokemon.level)) + else: + result = session.query(Pokemon).where(Pokemon.end_time > datetime.now() + self.timedelta) \ + .order_by(Pokemon.level) + session.commit() + return result.all() def sort_by_distance(self, location: Location, reverse=False): self.pokemons.sort(key=lambda pokemon: location.distance(pokemon.location), reverse=False) - def get_at(self, index:int): + def get_at(self, index: int): return self.pokemons[index] def search_by_name(self, query:str): diff --git a/main.py b/main.py index 857471b..258bc07 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,9 @@ from ispoof.objects.player import Player from ispoof.spoofer.scraper import Scraper from ispoof.spoofer.device import Device -from pymobiledevice3.exceptions import AlreadyMountedError from sqlalchemy import create_engine from ispoof.lists.pokemonlist import PokemonList from ispoof.data import initialize_database -from sqlalchemy.orm import Session import traceback if __name__ == "__main__":