fix: sort by cp and level

main
Khiem Ton 2 years ago
parent a6865f7a4a
commit c95dd99a5c
Signed by: th4tkh13m
GPG Key ID: 4D9CF147DCADD05D

@ -26,15 +26,31 @@ class PokemonList:
return result.all() return result.all()
def sort_by_cp(self, reverse=False): 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): 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): def sort_by_distance(self, location: Location, reverse=False):
self.pokemons.sort(key=lambda pokemon: location.distance(pokemon.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] return self.pokemons[index]
def search_by_name(self, query:str): def search_by_name(self, query:str):

@ -1,11 +1,9 @@
from ispoof.objects.player import Player from ispoof.objects.player import Player
from ispoof.spoofer.scraper import Scraper from ispoof.spoofer.scraper import Scraper
from ispoof.spoofer.device import Device from ispoof.spoofer.device import Device
from pymobiledevice3.exceptions import AlreadyMountedError
from sqlalchemy import create_engine from sqlalchemy import create_engine
from ispoof.lists.pokemonlist import PokemonList from ispoof.lists.pokemonlist import PokemonList
from ispoof.data import initialize_database from ispoof.data import initialize_database
from sqlalchemy.orm import Session
import traceback import traceback
if __name__ == "__main__": if __name__ == "__main__":

Loading…
Cancel
Save