From a1af7a6378a1b28fb8a08f86247970d799757d29 Mon Sep 17 00:00:00 2001 From: Eli White Date: Sat, 30 Jul 2016 23:06:36 -0700 Subject: [PATCH 1/7] Moving evolve_speed to task configuration --- configs/config.json.example | 6 ++++-- configs/config.json.path.example | 6 ++++-- configs/config.json.pokemon.example | 6 ++++-- pokecli.py | 2 +- pokemongo_bot/cell_workers/evolve_all.py | 8 ++++---- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/configs/config.json.example b/configs/config.json.example index db493eaff0..34ada4c5b2 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -21,7 +21,10 @@ "type": "TransferPokemon" }, { - "type": "EvolveAll" + "type": "EvolveAll", + "config": { + "evolve_speed": 20 + } }, { "type": "RecycleItems" @@ -66,7 +69,6 @@ "Razz Berry": { "keep" : 100 } }, "evolve_all": "NONE", - "evolve_speed": 20, "evolve_cp_min": 300, "use_lucky_egg": false, "evolve_captured": "NONE", diff --git a/configs/config.json.path.example b/configs/config.json.path.example index a29b1a6414..d798eaaab0 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -21,7 +21,10 @@ "type": "TransferPokemon" }, { - "type": "EvolveAll" + "type": "EvolveAll", + "config": { + "evolve_speed": 20 + } }, { "type": "RecycleItems" @@ -71,7 +74,6 @@ "701": { "keep" : 100 } }, "evolve_all": "NONE", - "evolve_speed": 20, "evolve_cp_min": 300, "use_lucky_egg": false, "evolve_captured": "NONE", diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index ebf7ba2a08..17973075b9 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -21,7 +21,10 @@ "type": "TransferPokemon" }, { - "type": "EvolveAll" + "type": "EvolveAll", + "config": { + "evolve_speed": 20 + } }, { "type": "RecycleItems" @@ -68,7 +71,6 @@ "701": { "keep" : 100 } }, "evolve_all": "NONE", - "evolve_speed": 20, "evolve_cp_min": 300, "use_lucky_egg": false, "evolve_captured": "NONE", diff --git a/pokecli.py b/pokecli.py index e225d78cab..4d2008a6db 100755 --- a/pokecli.py +++ b/pokecli.py @@ -408,7 +408,7 @@ def task_configuration_error(flag_name): """.format(flag_name)) old_flags = ['mode', 'catch_pokemon', 'spin_forts', 'forts_spin', 'hatch_eggs', 'release_pokemon', 'softban_fix', - 'longer_eggs_first'] + 'longer_eggs_first', 'evolve_speed'] for flag in old_flags: if flag in load: task_configuration_error(flag) diff --git a/pokemongo_bot/cell_workers/evolve_all.py b/pokemongo_bot/cell_workers/evolve_all.py index f92ce023ed..fbf5e37471 100644 --- a/pokemongo_bot/cell_workers/evolve_all.py +++ b/pokemongo_bot/cell_workers/evolve_all.py @@ -4,6 +4,9 @@ from pokemongo_bot.cell_workers.base_task import BaseTask class EvolveAll(BaseTask): + def initialize(self): + self.evolve_speed = self.config.get('evolve_speed', 3.7) + def work(self): if not self._should_run(): return @@ -154,10 +157,7 @@ def _execute_pokemon_evolve(self, pokemon, cache): pokemon_name, pokemon_cp, pokemon_iv )) - if self.bot.config.evolve_speed: - sleep(self.bot.config.evolve_speed) - else: - sleep(3.7) + sleep(self.evolve_speed) else: # cache pokemons we can't evolve. Less server calls From 81129d394fa7bf7913b2caf5b754d0ff42ed862a Mon Sep 17 00:00:00 2001 From: Eli White Date: Sat, 30 Jul 2016 23:47:13 -0700 Subject: [PATCH 2/7] Moving use_lucky_egg to be a task configuration --- configs/config.json.example | 4 ++-- configs/config.json.path.example | 4 ++-- configs/config.json.pokemon.example | 4 ++-- pokecli.py | 11 +---------- pokemongo_bot/cell_workers/evolve_all.py | 3 ++- 5 files changed, 9 insertions(+), 17 deletions(-) diff --git a/configs/config.json.example b/configs/config.json.example index 34ada4c5b2..7c250203d5 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -23,7 +23,8 @@ { "type": "EvolveAll", "config": { - "evolve_speed": 20 + "evolve_speed": 20, + "use_lucky_egg": true } }, { @@ -70,7 +71,6 @@ }, "evolve_all": "NONE", "evolve_cp_min": 300, - "use_lucky_egg": false, "evolve_captured": "NONE", "catch_randomize_reticle_factor": 1.0, "catch_randomize_spin_factor": 1.0, diff --git a/configs/config.json.path.example b/configs/config.json.path.example index d798eaaab0..29deee544c 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -23,7 +23,8 @@ { "type": "EvolveAll", "config": { - "evolve_speed": 20 + "evolve_speed": 20, + "use_lucky_egg": true } }, { @@ -75,7 +76,6 @@ }, "evolve_all": "NONE", "evolve_cp_min": 300, - "use_lucky_egg": false, "evolve_captured": "NONE", "catch_randomize_reticle_factor": 1.0, "catch_randomize_spin_factor": 1.0, diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 17973075b9..90dbdd5449 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -23,7 +23,8 @@ { "type": "EvolveAll", "config": { - "evolve_speed": 20 + "evolve_speed": 20, + "use_lucky_egg": true } }, { @@ -72,7 +73,6 @@ }, "evolve_all": "NONE", "evolve_cp_min": 300, - "use_lucky_egg": false, "evolve_captured": "NONE", "catch_randomize_reticle_factor": 1.0, "catch_randomize_spin_factor": 1.0, diff --git a/pokecli.py b/pokecli.py index 4d2008a6db..b2cc91e3eb 100755 --- a/pokecli.py +++ b/pokecli.py @@ -315,15 +315,6 @@ def init_config(): type=str, default=[] ) - add_config( - parser, - load, - short_flag="-le", - long_flag="--use_lucky_egg", - help="Uses lucky egg when using evolve_all", - type=bool, - default=False - ) add_config( parser, load, @@ -408,7 +399,7 @@ def task_configuration_error(flag_name): """.format(flag_name)) old_flags = ['mode', 'catch_pokemon', 'spin_forts', 'forts_spin', 'hatch_eggs', 'release_pokemon', 'softban_fix', - 'longer_eggs_first', 'evolve_speed'] + 'longer_eggs_first', 'evolve_speed', 'use_lucky_egg'] for flag in old_flags: if flag in load: task_configuration_error(flag) diff --git a/pokemongo_bot/cell_workers/evolve_all.py b/pokemongo_bot/cell_workers/evolve_all.py index fbf5e37471..8503c803c7 100644 --- a/pokemongo_bot/cell_workers/evolve_all.py +++ b/pokemongo_bot/cell_workers/evolve_all.py @@ -6,6 +6,7 @@ class EvolveAll(BaseTask): def initialize(self): self.evolve_speed = self.config.get('evolve_speed', 3.7) + self.use_lucky_egg = self.config.get('use_lucky_egg', False) def work(self): if not self._should_run(): @@ -53,7 +54,7 @@ def _should_run(self): return False # Evolve all is used - Don't run after the first tick or if the config flag is false - if self.bot.tick_count is not 1 or not self.bot.config.use_lucky_egg: + if self.bot.tick_count is not 1 or not self.use_lucky_egg: return True lucky_egg_count = self.bot.item_inventory_count(Item.ITEM_LUCKY_EGG.value) From d41f70ab8e8aa8e99686067c1270ad29bb66e8c4 Mon Sep 17 00:00:00 2001 From: Eli White Date: Sun, 31 Jul 2016 00:48:14 -0700 Subject: [PATCH 3/7] Fixing bug in evolve all. Fixes #2019 --- pokemongo_bot/cell_workers/evolve_all.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pokemongo_bot/cell_workers/evolve_all.py b/pokemongo_bot/cell_workers/evolve_all.py index 8503c803c7..2964fcd10b 100644 --- a/pokemongo_bot/cell_workers/evolve_all.py +++ b/pokemongo_bot/cell_workers/evolve_all.py @@ -150,8 +150,8 @@ def _execute_pokemon_evolve(self, pokemon, cache): if pokemon_name in cache: return - self.api.evolve_pokemon(pokemon_id=pokemon_id) - response_dict = self.api.call() + self.bot.api.evolve_pokemon(pokemon_id=pokemon_id) + response_dict = self.bot.api.call() status = response_dict['responses']['EVOLVE_POKEMON']['result'] if status == 1: print('[#] Successfully evolved {} with {} CP and {} IV!'.format( @@ -167,8 +167,8 @@ def _execute_pokemon_evolve(self, pokemon, cache): # TODO: move to utils. These methods are shared with other workers. def transfer_pokemon(self, pid): - self.api.release_pokemon(pokemon_id=pid) - response_dict = self.api.call() + self.bot.api.release_pokemon(pokemon_id=pid) + response_dict = self.bot.api.call() def count_pokemon_inventory(self): response_dict = self.bot.get_inventory() From bdaddec9ee64691e5b0a8bda55bf76f83442232f Mon Sep 17 00:00:00 2001 From: Eli White Date: Sun, 31 Jul 2016 01:07:58 -0700 Subject: [PATCH 4/7] Removing unused navigator switch --- pokemongo_bot/__init__.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index d18a0ee8c9..bd8c8e4f2e 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -53,11 +53,6 @@ def start(self): self._setup_logging() self._setup_api() - if self.config.navigator_type == 'spiral': - self.navigator = cell_workers.FollowSpiral - elif self.config.navigator_type == 'path': - self.navigator = cell_workers.FollowPath - random.seed() def _setup_event_system(self): From d5e787ce60b8238e9353dbd06cd91cededcdab39 Mon Sep 17 00:00:00 2001 From: kbinani Date: Mon, 1 Aug 2016 00:15:02 +0900 Subject: [PATCH 5/7] Avoid transferring favorite pokemons (#2038) --- pokemongo_bot/cell_workers/transfer_pokemon.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pokemongo_bot/cell_workers/transfer_pokemon.py b/pokemongo_bot/cell_workers/transfer_pokemon.py index 34e4518096..6caf0eafef 100644 --- a/pokemongo_bot/cell_workers/transfer_pokemon.py +++ b/pokemongo_bot/cell_workers/transfer_pokemon.py @@ -91,6 +91,10 @@ def _release_pokemon_get_groups(self): if 'deployed_fort_id' in pokemon_data and pokemon_data['deployed_fort_id']: continue + # favorite pokemon can't transfer in official game client + if pokemon_data.get('favorite', 0) is 1: + continue + group_id = pokemon_data['pokemon_id'] group_pokemon_cp = pokemon_data['cp'] group_pokemon_iv = self.get_pokemon_potential(pokemon_data) From eac7989d41cca4ee0289304f5b4b903e9ca4b6f3 Mon Sep 17 00:00:00 2001 From: achretien Date: Sun, 31 Jul 2016 17:17:22 +0200 Subject: [PATCH 6/7] Move follow path task config (#2044) --- configs/config.json.path.example | 11 +++++---- pokemongo_bot/cell_workers/follow_path.py | 27 ++++++++++++++--------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/configs/config.json.path.example b/configs/config.json.path.example index 29deee544c..ca74d166c3 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -43,7 +43,11 @@ "type": "MoveToFort" }, { - "type": "FollowSpiral" + "type": "FollowPath", + "config": { + "path_mode": "loop", + "path_file": "configs/path.example.json" + } } ], "max_steps": 5, @@ -51,11 +55,6 @@ "avoid_circles": true, "max_circle_size": 50 }, - "navigator": { - "type": "path", - "path_mode": "loop", - "path_file": "configs/path.example.json" - }, "websocket_server": false, "walk": 4.16, "action_wait_min": 1, diff --git a/pokemongo_bot/cell_workers/follow_path.py b/pokemongo_bot/cell_workers/follow_path.py index 4043ff085f..81a5d19695 100644 --- a/pokemongo_bot/cell_workers/follow_path.py +++ b/pokemongo_bot/cell_workers/follow_path.py @@ -14,19 +14,24 @@ class FollowPath(BaseTask): def initialize(self): self.ptr = 0 + self._process_config() self.points = self.load_path() + def _process_config(self): + self.path_file = self.config.get("path_file", None) + self.path_mode = self.config.get("path_mode", "linear") + def load_path(self): - if self.bot.config.navigator_path_file == None: + if self.path_file is None: raise RuntimeError('You need to specify a path file (json or gpx)') - if self.bot.config.navigator_path_file.endswith('.json'): - return self.load_json(self.bot.config.navigator_path_file) - elif self.bot.config.navigator_path_file.endswith('.gpx'): - return self.load_gpx(self.bot.config.navigator_path_file) + if self.path_file.endswith('.json'): + return self.load_json() + elif self.path_file.endswith('.gpx'): + return self.load_gpx() - def load_json(self, file): - with open(file) as data_file: + def load_json(self): + with open(self.path_file) as data_file: points=json.load(data_file) # Replace Verbal Location with lat&lng. logger.log("Resolving Navigation Paths (GeoLocating Strings)") @@ -40,8 +45,8 @@ def load_json(self, file): def lat_lng_tuple_to_dict(self, tpl): return {'lat': tpl[0], 'lng': tpl[1]} - def load_gpx(self, file): - gpx_file = open(file, 'r') + def load_gpx(self): + gpx_file = open(self.path_file, 'r') gpx = gpxpy.parse(gpx_file) if len(gpx.tracks) == 0: @@ -53,7 +58,7 @@ def load_gpx(self, file): for point in segment.points: points.append({"lat": point.latitude, "lng": point.longitude}) - return points; + return points def work(self): point = self.points[self.ptr] @@ -85,7 +90,7 @@ def work(self): if dist <= 1 or (self.bot.config.walk > 0 and is_at_destination): if (self.ptr + 1) == len(self.points): self.ptr = 0 - if self.bot.config.navigator_path_mode == 'linear': + if self.path_mode == 'linear': self.points = list(reversed(self.points)) else: self.ptr += 1 From a7523a1ef9064e2470be69fb1a73a2bbbfa75373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=E1=BA=A1m=20Ng=E1=BB=8Dc=20Quang=20Nam?= Date: Sun, 31 Jul 2016 22:24:16 +0700 Subject: [PATCH 7/7] Refactor (#1587) --- CONTRIBUTORS.md | 1 + pokemongo_bot/__init__.py | 136 ++++++++++++++------------------------ 2 files changed, 50 insertions(+), 87 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index d23ba72805..95f3415d41 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -43,3 +43,4 @@ * klingan * reddivision * kbinani + * NamPNQ diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index bd8c8e4f2e..c0db400fbe 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -133,7 +133,7 @@ def update_web_location(self, cells=[], lat=None, lng=None, alt=None): status = map_objects.get('status', None) cells = map_objects['map_cells'] - #insert detail info about gym to fort + # insert detail info about gym to fort for cell in cells: if 'forts' in cell: for fort in cell['forts']: @@ -159,7 +159,7 @@ def update_web_location(self, cells=[], lat=None, lng=None, alt=None): ) # alt is unused atm but makes using *location easier try: - with open(user_web_location,'w') as outfile: + with open(user_web_location, 'w') as outfile: json.dump({ 'lat': lat, 'lng': lng, @@ -389,25 +389,13 @@ def get_inventory(self): def update_inventory(self): response = self.get_inventory() self.inventory = list() - if 'responses' in response: - if 'GET_INVENTORY' in response['responses']: - if 'inventory_delta' in response['responses']['GET_INVENTORY']: - if 'inventory_items' in response['responses'][ - 'GET_INVENTORY']['inventory_delta']: - for item in response['responses']['GET_INVENTORY'][ - 'inventory_delta']['inventory_items']: - if not 'inventory_item_data' in item: - continue - if not 'item' in item['inventory_item_data']: - continue - if not 'item_id' in item['inventory_item_data'][ - 'item']: - continue - if not 'count' in item['inventory_item_data'][ - 'item']: - continue - self.inventory.append(item['inventory_item_data'][ - 'item']) + inventory_items = response.get('responses', {}).get('GET_INVENTORY', {}).get( + 'inventory_delta', {}).get('inventory_items', {}) + if inventory_items: + for item in inventory_items: + item_info = item.get('inventory_item_data', {}).get('item') + if {"item_id", "count"}.issubset(set(item_info.keys())): + self.inventory.append(item['inventory_item_data']['item']) def current_inventory(self): inventory_req = self.get_inventory() @@ -452,7 +440,7 @@ def _item_inventory_count_per_id(self, id, inventory_dict): item_dict = item.get('inventory_item_data', {}).get('item', {}) item_id = item_dict.get('item_id', False) item_count = item_dict.get('count', False) - if item_id == int(id) and item_count: + if item_id == int(id) and item_count: return item_count def _all_items_inventory_count(self, inventory_dict): @@ -547,8 +535,7 @@ def get_pos_by_name(self, location_name): '[x] Coordinates found in passed in location, ' 'not geocoding.' ) - return float(possible_coordinates[0]), \ - float(possible_coordinates[1]), float("0.0") + return float(possible_coordinates[0]), float(possible_coordinates[1]), float("0.0") geolocator = GoogleV3(api_key=self.config.gmapkey) loc = geolocator.geocode(location_name, timeout=10) @@ -567,28 +554,16 @@ def heartbeat(self): def get_inventory_count(self, what): response_dict = self.get_inventory() - if 'responses' in response_dict: - if 'GET_INVENTORY' in response_dict['responses']: - if 'inventory_delta' in response_dict['responses'][ - 'GET_INVENTORY']: - if 'inventory_items' in response_dict['responses'][ - 'GET_INVENTORY']['inventory_delta']: - pokecount = 0 - itemcount = 1 - for item in response_dict['responses'][ - 'GET_INVENTORY']['inventory_delta'][ - 'inventory_items']: - # print('item {}'.format(item)) - if 'inventory_item_data' in item: - if 'pokemon_data' in item[ - 'inventory_item_data']: - pokecount += 1 - if 'item' in item['inventory_item_data']: - if 'count' in item['inventory_item_data'][ - 'item']: - itemcount = itemcount + \ - item['inventory_item_data'][ - 'item']['count'] + inventory_items = response_dict.get('responses', {}).get('GET_INVENTORY', {}).get( + 'inventory_delta', {}).get('inventory_items', {}) + if inventory_items: + pokecount = 0 + itemcount = 1 + for item in inventory_items: + if 'inventory_item_data' in item: + if 'pokemon_data' in item['inventory_item_data']: + pokecount += 1 + itemcount += item['inventory_item_data'].get('item', {}).get('count', 0) if 'pokemon' in what: return pokecount if 'item' in what: @@ -597,47 +572,34 @@ def get_inventory_count(self, what): def get_player_info(self): response_dict = self.get_inventory() - if 'responses' in response_dict: - if 'GET_INVENTORY' in response_dict['responses']: - if 'inventory_delta' in response_dict['responses'][ - 'GET_INVENTORY']: - if 'inventory_items' in response_dict['responses'][ - 'GET_INVENTORY']['inventory_delta']: - pokecount = 0 - itemcount = 1 - for item in response_dict['responses'][ - 'GET_INVENTORY']['inventory_delta'][ - 'inventory_items']: - #print('item {}'.format(item)) - if 'inventory_item_data' in item: - if 'player_stats' in item[ - 'inventory_item_data']: - playerdata = item['inventory_item_data'][ - 'player_stats'] - - nextlvlxp = ( - int(playerdata.get('next_level_xp', 0)) - - int(playerdata.get('experience', 0))) - - if 'level' in playerdata: - if 'experience' in playerdata: - logger.log( - 'Level: {level}'.format( - **playerdata) + - ' (Next Level: {} XP)'.format( - nextlvlxp) + - ' (Total: {experience} XP)' - ''.format(**playerdata), 'cyan') - - if 'pokemons_captured' in playerdata: - if 'poke_stop_visits' in playerdata: - logger.log( - 'Pokemon Captured: ' - '{pokemons_captured}'.format( - **playerdata) + - ' | Pokestops Visited: ' - '{poke_stop_visits}'.format( - **playerdata), 'cyan') + inventory_items = response_dict.get('responses', {}).get('GET_INVENTORY', {}).get( + 'inventory_delta', {}).get('inventory_items', {}) + if inventory_items: + pokecount = 0 + itemcount = 1 + for item in inventory_items: + # print('item {}'.format(item)) + playerdata = item.get('inventory_item_data', {}).get('player_stats') + if playerdata: + nextlvlxp = (int(playerdata.get('next_level_xp', 0)) - int(playerdata.get('experience', 0))) + + if 'level' in playerdata and 'experience' in playerdata: + logger.log( + 'Level: {level}'.format( + **playerdata) + + ' (Next Level: {} XP)'.format( + nextlvlxp) + + ' (Total: {experience} XP)' + ''.format(**playerdata), 'cyan') + + if 'pokemons_captured' in playerdata and 'poke_stop_visits' in playerdata: + logger.log( + 'Pokemon Captured: ' + '{pokemons_captured}'.format( + **playerdata) + + ' | Pokestops Visited: ' + '{poke_stop_visits}'.format( + **playerdata), 'cyan') def has_space_for_loot(self): number_of_things_gained_by_stop = 5