From 0d80248c970c52b3cd1a582e2919d079d8bde434 Mon Sep 17 00:00:00 2001 From: Julien Deniau Date: Fri, 22 Jul 2016 16:47:22 +0200 Subject: [PATCH 1/7] group item by id --- pokemongo_bot/cell_workers/seen_fort_worker.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/seen_fort_worker.py b/pokemongo_bot/cell_workers/seen_fort_worker.py index 13fc49d..e00457b 100644 --- a/pokemongo_bot/cell_workers/seen_fort_worker.py +++ b/pokemongo_bot/cell_workers/seen_fort_worker.py @@ -58,8 +58,16 @@ def work(self): items_awarded = spin_details.get('items_awarded', False) if items_awarded: + tmp_count_items = {} for item in items_awarded: - item_id = str(item['item_id']) + item_id = item['item_id'] + if not item_id in tmp_count_items: + tmp_count_items[item_id] = item['item_count'] + else: + tmp_count_items[item_id] += item['item_count'] + + for item_id, item_count in tmp_count_items.iteritems(): + item_id = str(item_id) item_name = self.item_list[item_id] print_green("- " + str(item['item_count']) + "x " + item_name) else: From f129f3ba801e27291451b755841d1e84cce6d1d6 Mon Sep 17 00:00:00 2001 From: James Droste Date: Fri, 22 Jul 2016 15:49:14 +0100 Subject: [PATCH 2/7] Revert "Adding flask as a requirement due to #204" This reverts commit f383e11c9773bfedff7c0f1595ad6fd67a40686d. --- requirements.txt | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/requirements.txt b/requirements.txt index 36596cc..1aa47b0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,18 +1,8 @@ -click==6.6 -Flask==0.11.1 -Flask-Classy==0.6.10 -future==0.15.2 -geopy==1.11.0 -googlemaps==2.4.4 -gpsoauth==0.3.0 -itsdangerous==0.24 -Jinja2==2.8 -MarkupSafe==0.23 -e git://github.com/tejado/pgoapi.git@1f25e907f3e5f1b603330e71041e1ad7bee7580f#egg=pgoapi +geopy==1.11.0 protobuf==3.0.0b4 -protobuf-to-dict==0.1.0 -pycryptodomex==3.4.2 requests==2.10.0 s2sphere==0.2.4 -six==1.10.0 -Werkzeug==0.11.10 +gpsoauth==0.3.0 +protobuf-to-dict==0.1.0 +googlemaps==2.4.4 From 56a286410e20cbe10e1ab3e7c4ad2bf77e33d370 Mon Sep 17 00:00:00 2001 From: James Droste Date: Fri, 22 Jul 2016 15:49:21 +0100 Subject: [PATCH 3/7] Revert "Adding initial REST Framework; Adding method to get user stats (#204)" This reverts commit 81ea15298b8e362f2b22019aad3bae9862713165. --- pokecli.py | 11 ++--------- pokemongo_bot/__init__.py | 21 ++++++--------------- server.py | 30 ------------------------------ 3 files changed, 8 insertions(+), 54 deletions(-) delete mode 100644 server.py diff --git a/pokecli.py b/pokecli.py index c01607f..5356fe4 100755 --- a/pokecli.py +++ b/pokecli.py @@ -39,7 +39,6 @@ ssl._create_default_https_context = ssl._create_unverified_context from pokemongo_bot import PokemonGoBot -from server import PokemonGoServer def init_config(): parser = argparse.ArgumentParser() @@ -97,14 +96,8 @@ def main(): bot = PokemonGoBot(config) bot.start() - pid = os.fork() - - if pid == 0: - server = PokemonGoServer(bot, 5000) - server.start() - else: - while(True): - bot.take_step() + while(True): + bot.take_step() if __name__ == '__main__': main() diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 84be0a0..69e5e83 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -11,7 +11,6 @@ from stepper import Stepper from geopy.geocoders import GoogleV3 from math import radians, sqrt, sin, cos, atan2 -from collections import OrderedDict class PokemonGoBot(object): @@ -249,10 +248,7 @@ def get_inventory_count(self, what): return itemcount return '0' - def get_player_info(self, print_stats=True): - player_stats = stats = OrderedDict() - - # Get contents of inventory + def get_player_info(self): self.api.get_inventory() response_dict = self.api.call() if 'responses' in response_dict: @@ -270,19 +266,14 @@ def get_player_info(self, print_stats=True): nextlvlxp = (int(playerdata['next_level_xp']) - int(playerdata['experience'])) if 'level' in playerdata: - player_stats['Level'] = playerdata['level'] + print('[#] -- Level: {level}'.format(**playerdata)) if 'experience' in playerdata: - player_stats['Experience'] = playerdata['experience'] - player_stats['Experience until next level'] = nextlvlxp + print('[#] -- Experience: {experience}'.format(**playerdata)) + print('[#] -- Experience until next level: {}'.format(nextlvlxp)) if 'pokemons_captured' in playerdata: - player_stats['Pokemon Captured'] = playerdata['pokemons_captured'] + print('[#] -- Pokemon Captured: {pokemons_captured}'.format(**playerdata)) if 'poke_stop_visits' in playerdata: - player_stats['Pokestops Visited'] = playerdata['poke_stop_visits'] - - if print_stats: - for key in player_stats: - print('[#] -- {}: {}'.format(key, player_stats[key])) - return json.dumps(player_stats, indent=4) + print('[#] -- Pokestops Visited: {poke_stop_visits}'.format(**playerdata)) diff --git a/server.py b/server.py deleted file mode 100644 index 1198f16..0000000 --- a/server.py +++ /dev/null @@ -1,30 +0,0 @@ -import json - -from flask import Flask -from flask.ext.classy import FlaskView, route -#from bot import PokemonGoBot - -from pgoapi import PGoApi - -app = Flask(__name__) - -global global_bot - -class PokemonGoServer(object): - def __init__(self, bot, port=5000): - api_view = ApiView() - api_view.set_bot(bot) - api_view.register(app) - self.port = port - - def start(self): - app.run(host='0.0.0.0', port=self.port) - -class ApiView(FlaskView): - def set_bot(self, bot): - global global_bot - global_bot = bot - - @route("/player_info") - def get_player_info(self): - return global_bot.get_player_info(False) From 17a15bf638519feb66efb6f2f5305406a17c797e Mon Sep 17 00:00:00 2001 From: Darron Eggins Date: Sat, 23 Jul 2016 00:51:25 +1000 Subject: [PATCH 4/7] reverting test code before i left - this will throw errors for people to look at. --- pokemongo_bot/cell_workers/pokemon_catch_worker.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index 5566e1c..7fb4182 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -77,12 +77,18 @@ def work(self): if cp < self.config.cp: print_green('[x] Captured ' + str(pokemon_name) + '! [CP' + str(cp) + '] - exchanging for candy') id_list2 = self.count_pokemon_inventory() +<<<<<<< 56a286410e20cbe10e1ab3e7c4ad2bf77e33d370 try: # Transfering Pokemon self.transfer_pokemon(list(Set(id_list2) - Set(id_list1))[0]) except: print_red('[###] Your inventory is full! Please manually delete some items.') break +======= + # Transfering Pokemon + self.transfer_pokemon(list(Set(id_list2) - Set(id_list1))[0]) + +>>>>>>> reverting test code before i left - this will throw errors for people to look at. else: print_green('[x] Captured ' + str(pokemon_name) + '! [CP' + str(cp) + ']') break From a222b0922890c96ecdfb2f79b452745086fd73d1 Mon Sep 17 00:00:00 2001 From: Darron Eggins Date: Sat, 23 Jul 2016 00:53:36 +1000 Subject: [PATCH 5/7] fix merge issues --- .../cell_workers/pokemon_catch_worker.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index 7fb4182..1f358e1 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -77,18 +77,11 @@ def work(self): if cp < self.config.cp: print_green('[x] Captured ' + str(pokemon_name) + '! [CP' + str(cp) + '] - exchanging for candy') id_list2 = self.count_pokemon_inventory() -<<<<<<< 56a286410e20cbe10e1ab3e7c4ad2bf77e33d370 - try: - # Transfering Pokemon - self.transfer_pokemon(list(Set(id_list2) - Set(id_list1))[0]) - except: - print_red('[###] Your inventory is full! Please manually delete some items.') - break -======= # Transfering Pokemon - self.transfer_pokemon(list(Set(id_list2) - Set(id_list1))[0]) - ->>>>>>> reverting test code before i left - this will throw errors for people to look at. + + ## TODO - FIX TRANSFERRING OF POKEMON + # self.transfer_pokemon(list(Set(id_list2) - Set(id_list1))[0]) + print('[#####] POKEMON NOT EXCHANGED. THIS CODE NEEDS TO BE LOOKED AT') else: print_green('[x] Captured ' + str(pokemon_name) + '! [CP' + str(cp) + ']') break From 1ad202b4e19f27126aa8ebcd123191817454e7ff Mon Sep 17 00:00:00 2001 From: Reaver01 Date: Fri, 22 Jul 2016 17:02:40 +0200 Subject: [PATCH 6/7] web 1.1 (#210) --- pokemongo_bot/human_behaviour.py | 2 +- pokemongo_bot/stepper.py | 6 +++--- web/index.html | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pokemongo_bot/human_behaviour.py b/pokemongo_bot/human_behaviour.py index dcbc732..88c2b5b 100644 --- a/pokemongo_bot/human_behaviour.py +++ b/pokemongo_bot/human_behaviour.py @@ -4,7 +4,7 @@ def sleep(seconds, delta=0.3): jitter = ceil(delta * seconds) - sleep_time = randint(seconds-jitter, seconds+jitter) + sleep_time = randint(int(seconds-jitter), int(seconds+jitter)) time.sleep(sleep_time) def random_lat_long_delta(): diff --git a/pokemongo_bot/stepper.py b/pokemongo_bot/stepper.py index 892ccac..1cc470b 100644 --- a/pokemongo_bot/stepper.py +++ b/pokemongo_bot/stepper.py @@ -45,7 +45,9 @@ def take_step(self): self._walk_to(self.config.walk, *position) else: self.api.set_position(*position) - print(position) + print('[#] {}'.format(position)) + with open('web/location.json', 'w') as outfile: + json.dump({'lat': position[0], 'lng': position[1]}, outfile) if self.x == self.y or self.x < 0 and self.x == -self.y or self.x > 0 and self.x == 1 - self.y: (self.dx, self.dy) = (-self.dy, self.dx) @@ -57,8 +59,6 @@ def take_step(self): cellid = self._get_cellid(position[0], position[1]) timestamp = [0,] * len(cellid) self.api.get_map_objects(latitude=f2i(position[0]), longitude=f2i(position[1]), since_timestamp_ms=timestamp, cell_id=cellid) - with open('web/location.json', 'w') as outfile: - json.dump({'lat': position[0], 'lng': position[1]}, outfile) response_dict = self.api.call() if response_dict and 'responses' in response_dict and \ diff --git a/web/index.html b/web/index.html index aa03b00..0ae39e0 100644 --- a/web/index.html +++ b/web/index.html @@ -36,23 +36,23 @@ } function placeTrainer() { loadJSON('location.json', - function(data) { loc = data; map.setZoom(16); map.panTo({lat: parseInt(loc.lat), lng: parseInt(loc.lng)}); }, + function(data) { loc = data; map.setZoom(16); map.panTo({lat: parseFloat(loc.lat), lng: parseFloat(loc.lng)}); }, function(xhr) { console.error(xhr);} ); console.log("New Marker: Trainer - " + loc.lat + ", " + loc.lng); marker = new google.maps.Marker({ map: map, - position: {lat: parseInt(loc.lat), lng: parseInt(loc.lng)}, + position: {lat: parseFloat(loc.lat), lng: parseFloat(loc.lng)}, icon: "image/trainer-icon.png" }); } function updateTrainer() { loadJSON('location.json', - function(data) { loc = data; map.panTo({lat: parseInt(loc.lat), lng: parseInt(loc.lng)}); }, + function(data) { loc = data; map.panTo({lat: parseFloat(loc.lat), lng: parseFloat(loc.lng)}); }, function(xhr) { console.error(xhr);} ); console.log("Move Marker: Trainer - " + loc.lat + ", " + loc.lng); - marker.setPosition({lat: parseInt(loc.lat), lng: parseInt(loc.lng)}); + marker.setPosition({lat: parseFloat(loc.lat), lng: parseFloat(loc.lng)}); } function loadJSON(path, success, error) { var xhr = new XMLHttpRequest(); From 48aa2a150f7c1074d6ef3018c7b4f057cf6a172c Mon Sep 17 00:00:00 2001 From: Darron Eggins Date: Sat, 23 Jul 2016 01:11:14 +1000 Subject: [PATCH 7/7] fixed pokemon transferring issue and created pretty-print --- pokemongo_bot/cell_workers/pokemon_catch_worker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index 1f358e1..e7d5585 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -80,8 +80,8 @@ def work(self): # Transfering Pokemon ## TODO - FIX TRANSFERRING OF POKEMON - # self.transfer_pokemon(list(Set(id_list2) - Set(id_list1))[0]) - print('[#####] POKEMON NOT EXCHANGED. THIS CODE NEEDS TO BE LOOKED AT') + self.transfer_pokemon(list(Set(id_list2) - Set(id_list1))) + print_green('[#] ' + str(pokemon_name) + ' has been exchanged for candy!') else: print_green('[x] Captured ' + str(pokemon_name) + '! [CP' + str(cp) + ']') break