fix: sort by cp and level

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

@ -26,10 +26,26 @@ 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)

@ -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__":

Loading…
Cancel
Save