diff --git a/ispoof/lists/playerhistory.py b/ispoof/lists/playerhistory.py index f785adc..0758574 100644 --- a/ispoof/lists/playerhistory.py +++ b/ispoof/lists/playerhistory.py @@ -24,6 +24,7 @@ class PlayerHistory(Base): if result: time, location = result.time, result.location session.commit() + session.close() return time, location @@ -33,4 +34,5 @@ class PlayerHistory(Base): self.location = location session.add(self) session.commit() + session.close() return True diff --git a/ispoof/lists/pokemonlist.py b/ispoof/lists/pokemonlist.py index 4749aff..e14789e 100644 --- a/ispoof/lists/pokemonlist.py +++ b/ispoof/lists/pokemonlist.py @@ -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() diff --git a/ispoof/lists/raidlist.py b/ispoof/lists/raidlist.py index 5ad3f76..901a72b 100644 --- a/ispoof/lists/raidlist.py +++ b/ispoof/lists/raidlist.py @@ -25,6 +25,7 @@ class RaidList: result = session.query(Raid).where(Raid.end_time > datetime.now() + self.timedelta) \ .order_by(Raid.name) session.commit() + session.close() return result.all() def sort_by_level(self, reverse=False): @@ -36,18 +37,21 @@ class RaidList: result = session.query(Raid).where(Raid.end_time > datetime.now() + self.timedelta) \ .order_by(Raid.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(Raid).where(Raid.end_time > datetime.now() + self.timedelta) session.commit() + session.close() return sorted(result.all(), key=lambda raid: location.distance(raid.location), reverse=reverse) def search_by_name(self, query: str): with Session(self.engine) as session: result = session.query(Raid).where(Raid.end_time > datetime.now() + self.timedelta) session.commit() + session.close() return list(filter(lambda raid: partial_ratio(query.lower(), raid.name) >= 80, result.all())) def insert_to_database(self, raids: List[Raid]): @@ -55,4 +59,5 @@ class RaidList: with Session(self.engine) as session: session.add_all(raids) session.commit() + session.close()