From 61a723a9b169f6043384e0f97c7fe5e822428d16 Mon Sep 17 00:00:00 2001 From: Daniel Mateus Pires Date: Sat, 23 Jul 2016 10:42:02 +0100 Subject: [PATCH 1/3] Adding timeout to Geo service --- pokemongo_bot/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 79e3bcbf10..cb4054dcde 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -212,7 +212,7 @@ def _set_starting_position(self): def _get_pos_by_name(self, location_name): geolocator = GoogleV3(api_key=self.config.gmapkey) - loc = geolocator.geocode(location_name) + loc = geolocator.geocode(location_name, timeout=10) #self.log.info('Your given location: %s', loc.address.encode('utf-8')) #self.log.info('lat/long/alt: %s %s %s', loc.latitude, loc.longitude, loc.altitude) From c411baad4d205259d39a33ea9c0942893703ad6f Mon Sep 17 00:00:00 2001 From: Daniel Mateus Pires Date: Sat, 23 Jul 2016 12:58:44 +0100 Subject: [PATCH 2/3] Normalised the config parameters and updated config.json, added a last location json dump for every bot so you can start each one of them at their last location --- .gitignore | 12 ++++++++++-- README.md | 1 + config.json.example | 19 +++++++++++-------- pokecli.py | 18 ++++++++---------- pokemongo_bot/__init__.py | 2 +- pokemongo_bot/stepper.py | 5 ++++- web/userdata.js | 4 ---- 7 files changed, 35 insertions(+), 26 deletions(-) delete mode 100644 web/userdata.js diff --git a/.gitignore b/.gitignore index a65c0694af..003dde0c6a 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,12 @@ var/ *.manifest *.spec +# Eclipse Users +.project +.pydevproject +.settings/ + + # Installer logs pip-log.txt pip-delete-this-directory.txt @@ -90,15 +96,17 @@ ENV/ # Personal load details config.json -location.json src/ info.json inventory.json pokedex.json web/catchable.json -data/catch-ignore.yml web/catchable-*.json web/location-*.json +web/location.json +web/userdata.js +data/last-location*.json +data/catch-ignore.yml # ignore Pycharm config .idea diff --git a/README.md b/README.md index 774c4ebd7a..5f93b63510 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,7 @@ To install the pgoapi use `pip install -e git://github.com/tejado/pgoapi.git#egg * mzupan * namlehong * gnekic(GeXx) + * dmateusp ## Credits [tejado](https://github.com/tejado) many thanks for the API diff --git a/config.json.example b/config.json.example index d9ec77e6da..66aed50122 100644 --- a/config.json.example +++ b/config.json.example @@ -1,14 +1,17 @@ { "auth_service": "google", - "username": "example@gmail.com", - "password": "password11!!", - "location": "New York", + "username": "YOURACCOUNT@gmail.com", + "password": "YOURPASSWORD", + "location": "SOME LOCATION", "cp": 100, - "gmapkey": "CHANGME", - "maxsteps": 100, + "gmapkey": "AGMAPAPIKEY", + "max_steps": 50, "mode": "all", "walk": 4.16, - "debug": true, - "test": false + "debug": false, + "test": false, + "initial_transfer": false, + "pokemon_potential": 0.70, + "location_cache": true, + "distance_unit": "km" } - diff --git a/pokecli.py b/pokecli.py index dde4aa4ced..f5bbde9bf5 100755 --- a/pokecli.py +++ b/pokecli.py @@ -60,20 +60,18 @@ def init_config(): parser.add_argument("-u", "--username", help="Username") parser.add_argument("-p", "--password", help="Password") parser.add_argument("-l", "--location", help="Location") - parser.add_argument("-lc", "--use-location-cache", help="Bot will start at last known location", action='store_true', default=False, dest='location_cache') + parser.add_argument("-lc", "--location_cache", help="Bot will start at last known location", type=bool, default=False) parser.add_argument("-m", "--mode", help="Farming Mode", type=str, default="all") parser.add_argument("-w", "--walk", help="Walk instead of teleport with given speed (meters per second, e.g. 2.5)", type=float, default=2.5) parser.add_argument("-c", "--cp",help="Set CP less than to transfer(DEFAULT 100)",type=int,default=100) parser.add_argument("-iv", "--pokemon_potential",help="Set IV ratio less than to transfer(DEFAULT 0.80)",type=float,default=0.80) - parser.add_argument("-k", "--gmapkey",help="Set Google Maps API KEY",type=str,default=None) - parser.add_argument("--maxsteps",help="Set the steps around your initial location(DEFAULT 5 mean 25 cells around your location)",type=int,default=5) - parser.add_argument("--initial-transfer", help="Transfer all pokemon with same ID on bot start, except pokemon with highest CP. It works with -c", action='store_true', dest='initial_transfer') - parser.add_argument("-d", "--debug", help="Debug Mode", action='store_true') - parser.add_argument("-t", "--test", help="Only parse the specified location", action='store_true') - parser.add_argument("--distance_unit", help="Set the unit to display distance in (e.g, km for kilometers, mi for miles, ft for feet)", type=str, default="m") - parser.set_defaults(DEBUG=False, TEST=False) + parser.add_argument("-k", "--gmapkey",help="Set Google Maps API KEY",type=str, default=None) + parser.add_argument("-ms","--max_steps",help="Set the steps around your initial location(DEFAULT 5 mean 25 cells around your location)",type=int,default=50) + parser.add_argument("-it", "--initial_transfer", help="Transfer all pokemon with same ID on bot start, except pokemon with highest CP. It works with -c", type=bool, default=False) + parser.add_argument("-d", "--debug", help="Debug Mode", type=bool, default=False) + parser.add_argument("-t", "--test", help="Only parse the specified location", type=bool, default=False) + parser.add_argument("-du","--distance_unit", help="Set the unit to display distance in (e.g, km for kilometers, mi for miles, ft for feet)", type=str, default="km") config = parser.parse_args() - if not config.username and not 'username' in load: config.username = raw_input("Username: ") if not config.password and not 'password' in load: @@ -91,7 +89,7 @@ def init_config(): if not config.location and not config.location_cache in load: logging.error("Needs either --use-location-cache or --location.") return None - + print(config) return config def main(): diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 35766c9470..8a944c9cd0 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -280,7 +280,7 @@ def _set_starting_position(self): try: # # save location flag used to pull the last known location from the location.json - with open('location.json') as f: + with open('data/last-location-%s.json' % (self.config.username)) as f: location_json = json.load(f) self.position = (location_json['lat'], location_json['lng'], 0.0) diff --git a/pokemongo_bot/stepper.py b/pokemongo_bot/stepper.py index f11b703e1a..2f030fc759 100644 --- a/pokemongo_bot/stepper.py +++ b/pokemongo_bot/stepper.py @@ -25,7 +25,7 @@ def __init__(self, bot): self.y = 0 self.dx = 0 self.dy = -1 - self.steplimit=self.config.maxsteps + self.steplimit=self.config.max_steps self.steplimit2 = self.steplimit**2 self.origin_lat = self.bot.position[0] self.origin_lon = self.bot.position[1] @@ -90,6 +90,9 @@ def _work_at_position(self, lat, lng, alt, pokemon_only=False): if 'map_cells' in response_dict['responses']['GET_MAP_OBJECTS']: with open('web/location-%s.json' % (self.config.username), 'w') as outfile: json.dump({'lat': lat, 'lng': lng,'cells':response_dict['responses']['GET_MAP_OBJECTS']['map_cells']}, outfile) + with open('data/last-location-%s.json' % (self.config.username), 'w') as outfile: + outfile.truncate() + json.dump({'lat': lat, 'lng' : lng},outfile) if response_dict and 'responses' in response_dict: if 'GET_MAP_OBJECTS' in response_dict['responses']: if 'status' in response_dict['responses']['GET_MAP_OBJECTS']: diff --git a/web/userdata.js b/web/userdata.js deleted file mode 100644 index 8147a0a8c4..0000000000 --- a/web/userdata.js +++ /dev/null @@ -1,4 +0,0 @@ -// MUST CONFIGURE THE USER ARRAY. -var users = ["username"]; -var userZoom = true; -var userFollow = true; \ No newline at end of file From 3937b50f35ece9f5bf3cf68c0697d6113648a011 Mon Sep 17 00:00:00 2001 From: julesferreira Date: Sat, 23 Jul 2016 06:30:18 -0600 Subject: [PATCH 3/3] ensure cell has pokestops before trying to iterate over them (#419) --- web/main.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web/main.js b/web/main.js index 485231381a..8e1fbc67a0 100644 --- a/web/main.js +++ b/web/main.js @@ -55,6 +55,9 @@ var trainerFunc = function(data, user_index) { var z = 0; for (var i = 0; i < data.cells.length; i++) { cell = data.cells[i]; + if (!cell.hasOwnProperty(forts)) { + continue; + } for (var x = 0; x < data.cells[i].forts.length; x++) { var fort = cell.forts[x]; if (!forts[fort.id]) {