Skip to content

Commit

Permalink
Bulktransfer improvement.
Browse files Browse the repository at this point in the history
  • Loading branch information
walaoaaa1234 committed Apr 4, 2017
1 parent 25bff50 commit f053ad5
Showing 1 changed file with 77 additions and 21 deletions.
98 changes: 77 additions & 21 deletions pokemongo_bot/cell_workers/pokemon_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,13 +699,15 @@ def transfer_pokemon(self, transfer):
4: 'ERROR_POKEMON_IS_EGG',
5: 'ERROR_POKEMON_IS_BUDDY'
}
pokemons = list(transfer)
if self.config_bulktransfer_enabled and len(pokemons) > 1:
while len(pokemons) > 0:
action_delay(self.config_action_wait_min, self.config_action_wait_max)
pokemon_ids = []
count = 0
transfered = []
while len(pokemons) > 0 and count < self.config_max_bulktransfer:
pokemon = pokemons.pop()
transfered.append(pokemon)
pokemon_ids.append(pokemon.unique_id)
count = count + 1
try:
Expand All @@ -717,32 +719,86 @@ def transfer_pokemon(self, transfer):
return False
except Exception:
return False
for pokemon in transfer:
candy = inventory.candies().get(pokemon.pokemon_id)

for x in transfered:
candy = inventory.candies().get(x.pokemon_id)

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

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

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

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})
if self.config_transfer:
inventory.pokemons().remove(x.unique_id)

if self.config_transfer:
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 (?, ?, ?)", (x.name, x.iv, x.cp))

if db_result[0] == 1:
db.execute("INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)", (pokemon.name, pokemon.iv, pokemon.cp))
else:error_codes = {
0: 'UNSET',
1: 'SUCCESS',
2: 'POKEMON_DEPLOYED',
3: 'FAILED',
4: 'ERROR_POKEMON_IS_EGG',
5: 'ERROR_POKEMON_IS_BUDDY'
}
if self.config_bulktransfer_enabled and len(pokemons) > 1:
while len(pokemons) > 0:
action_delay(self.config_action_wait_min, self.config_action_wait_max)
pokemon_ids = []
count = 0
transfered = []
while len(pokemons) > 0 and count < self.config_max_bulktransfer:
pokemon = pokemons.pop()
transfered.append(pokemon)
pokemon_ids.append(pokemon.unique_id)
count = count + 1
try:
if self.config_transfer:
response_dict = self.bot.api.release_pokemon(pokemon_ids=pokemon_ids)
result = response_dict['responses']['RELEASE_POKEMON']['result']
if result != 1:
self.logger.error(u'Error while transfer pokemon: {}'.format(error_codes[result]))
return False
except Exception:
return False

for x in transfered:
candy = inventory.candies().get(x.pokemon_id)

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

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

if self.config_transfer:
inventory.pokemons().remove(x.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'")

db_result = cursor.fetchone()

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

action_delay(self.config_action_wait_min, self.config_action_wait_max)
else:
for pokemon in pokemons:
if self.config_transfer and (not self.bot.config.test):
Expand Down

0 comments on commit f053ad5

Please sign in to comment.