Skip to content

Commit

Permalink
Merge pull request #5987 from walaoaaa1234/bulktransfer
Browse files Browse the repository at this point in the history
Bulk Transfer
  • Loading branch information
pogarek authored Mar 31, 2017
2 parents 16f4e2b + 70df546 commit 34d0ff4
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions pokemongo_bot/cell_workers/pokemon_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,7 @@ def apply_optimization(self, transfer, evolve, upgrade, xp):
if transfer_count > 0:
self.logger.info("Transferring %s Pokemon", transfer_count)

for pokemon in transfer:
self.transfer_pokemon(pokemon)
self.transfer_pokemon(transfer)

if self.config_evolve or self.bot.config.test:
evolve_xp_count = evolve_count + xp_count
Expand Down Expand Up @@ -690,40 +689,38 @@ def apply_optimization(self, transfer, evolve, upgrade, xp):
self.upgrade_pokemon(pokemon)

def transfer_pokemon(self, pokemon):
pokemon_ids = []
for pokemon in transfer:
pokemon_ids.extend([pokemon.unique_id])

if self.config_transfer and (not self.bot.config.test):
response_dict = self.bot.api.release_pokemon(pokemon_id=pokemon.unique_id)
response_dict = self.bot.api.release_pokemon(pokemon_ids=pokemon_ids)
else:
response_dict = {"responses": {"RELEASE_POKEMON": {"candy_awarded": 0}}}

if not response_dict:
return False

candy_awarded = response_dict.get("responses", {}).get("RELEASE_POKEMON", {}).get("candy_awarded", 0)
candy = inventory.candies().get(pokemon.pokemon_id)

if self.config_transfer and (not self.bot.config.test):
candy.add(candy_awarded)

self.emit_event("pokemon_release",
formatted="Exchanged {pokemon} [IV {iv}] [CP {cp}] [{candy} candies]",
data={"pokemon": pokemon.name,
"iv": pokemon.iv,
"cp": pokemon.cp,
"candy": candy.quantity})
for pokemon in transfer:
self.emit_event("pokemon_release",
formatted="Exchanged {pokemon} [IV {iv}] [CP {cp}]",
data={"pokemon": pokemon.name,
"iv": pokemon.iv,
"cp": pokemon.cp})

if self.config_transfer and (not self.bot.config.test):
inventory.pokemons().remove(pokemon.unique_id)
if self.config_transfer and (not self.bot.config.test):
inventory.pokemons().remove(pokemon.unique_id)

with self.bot.database as db:
cursor = db.cursor()
cursor.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='transfer_log'")
with self.bot.database as db:
cursor = db.cursor()
cursor.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='transfer_log'")

db_result = cursor.fetchone()
db_result = cursor.fetchone()

if db_result[0] == 1:
db.execute("INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)", (pokemon.name, pokemon.iv, pokemon.cp))
if db_result[0] == 1:
db.execute("INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)", (pokemon.name, pokemon.iv, pokemon.cp))

action_delay(self.config_action_wait_min, self.config_action_wait_max)
action_delay(self.config_action_wait_min, self.config_action_wait_max)

return True

Expand Down

0 comments on commit 34d0ff4

Please sign in to comment.