Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
* pulgalipe
* BartKoppelmans
* VictorChen
* AlvaroGzP
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Option | Meaning
`walk` | Set the walking speed in kilometers per hour.(14km/h is the maximum speed for egg hatching)
`debug` | Let the default value here except if you are developer
`test` | Let the default value here except if you are developer
`initial_transfer` | Set this to an upper bound of the cp level which you want to transfer at the beginning of the run. For example, set the value to 0 to disable the initial transfer, set it to 100 to enable initial transfer for cp levels 0-99. It will still transfer pokémon during your exploration, depending on how your release_config.json is setup.
`initial_transfer` | Set this to true to transfer your pokemons at the beginning of the run based on your release config.
`location_cache` | Bot will start at last known location if you do not have location set in the config
`distance_unit` | Set the unit to display distance in (e.g, km for kilometers, mi for miles, ft for feet)
`item_filter` | Pass a list of unwanted items (in CSV format) to recycle when collected at a Pokestop (e.g, "101,102,103,104" to recycle potions when collected)
Expand Down
2 changes: 1 addition & 1 deletion configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"walk": 4.16,
"debug": false,
"test": false,
"initial_transfer": 0,
"initial_transfer": false,
"location_cache": true,
"distance_unit": "km",
"item_filter": {
Expand Down
2 changes: 1 addition & 1 deletion configs/config.json.pokemons.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"walk": 4.16,
"debug": false,
"test": false,
"initial_transfer": 0,
"initial_transfer": false,
"location_cache": true,
"distance_unit": "km",
"item_filter": {
Expand Down
96 changes: 78 additions & 18 deletions pokemongo_bot/cell_workers/initial_transfer_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ def __init__(self, bot):
self.api = bot.api

def work(self):
logger.log('Cleaning up Pokemon Bag of anything below {} CP'.format(
self.config.initial_transfer), 'cyan')
if not self.config.initial_transfer:
return

logger.log('Cleaning up Pokemon Bag using the release config', 'cyan')

pokemon_groups = self._initial_transfer_get_groups()

Expand All @@ -25,15 +27,17 @@ def work(self):


for x in range(1, len(group_cp)):
if self.config.initial_transfer and group_cp[x] > self.config.initial_transfer:
continue

logger.log('Exchanging {} with {} CP'.format(
self.pokemon_list[id - 1]['Name'], group_cp[x]))
self.api.release_pokemon(
pokemon_id=pokemon_groups[id][group_cp[x]])
response_dict = self.api.call()
sleep(2)
pokemon_name = self.pokemon_list[id - 1]['Name']
pokemon_cp = group_cp[x]
pokemon_data = pokemon_groups[id][pokemon_cp]
pokemon_potential = self.get_pokemon_potential(pokemon_data)
if self.should_release_pokemon(pokemon_name, pokemon_cp, pokemon_potential):
logger.log('Exchanging {} [CP {}] [Potential {}]'.format(
pokemon_name, pokemon_cp, pokemon_potential))
self.api.release_pokemon(
pokemon_id=pokemon_data['id'])
response_dict = self.api.call()
sleep(2)

logger.log('Pokemon Bag has been cleaned up!', 'green')

Expand All @@ -56,15 +60,71 @@ def _initial_transfer_get_groups(self):
except KeyError:
continue

group_id = pokemon['inventory_item_data'][
'pokemon_data']['pokemon_id']
group_pokemon = pokemon['inventory_item_data'][
'pokemon_data']['id']
group_pokemon_cp = pokemon[
'inventory_item_data']['pokemon_data']['cp']
pokemon_data = pokemon['inventory_item_data']['pokemon_data']
group_id = pokemon_data['pokemon_id']
group_pokemon_cp = pokemon_data['cp']

if group_id not in pokemon_groups:
pokemon_groups[group_id] = {}

pokemon_groups[group_id].update({group_pokemon_cp: group_pokemon})
pokemon_groups[group_id].update({group_pokemon_cp: pokemon_data})
return pokemon_groups

def get_pokemon_potential(self, pokemon_data):
total_iv = 0
iv_stats = ['individual_attack', 'individual_defense', 'individual_stamina']
for individual_stat in iv_stats:
try:
total_iv += pokemon_data[individual_stat]
except:
continue
return round((total_iv / 45.0), 2)

def should_release_pokemon(self, pokemon_name, cp, iv):
release_config = self._get_release_config_for(pokemon_name)
cp_iv_logic = release_config.get('logic')
if not cp_iv_logic:
cp_iv_logic = self._get_release_config_for('any').get('logic', 'and')

release_results = {
'cp': False,
'iv': False,
}

if release_config.get('never_release', False):
return False

if release_config.get('always_release', False):
return True

release_cp = release_config.get('release_below_cp', 0)
if cp < release_cp:
release_results['cp'] = True

release_iv = release_config.get('release_below_iv', 0)
if iv < release_iv:
release_results['iv'] = True

logic_to_function = {
'or': lambda x, y: x or y,
'and': lambda x, y: x and y
}

#logger.log(
# "Release config for {}: CP {} {} IV {}".format(
# pokemon_name,
# min_cp,
# cp_iv_logic,
# min_iv
# ), 'yellow'
#)

return logic_to_function[cp_iv_logic](*release_results.values())

def _get_release_config_for(self, pokemon):
release_config = self.config.release.get(pokemon)
if not release_config:
release_config = self.config.release.get('any')
if not release_config:
release_config = {}
return release_config