-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a navigator that walks along specified points.
- Loading branch information
1 parent
c6652f2
commit 8e7310e
Showing
9 changed files
with
207 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"auth_service": "google", | ||
"username": "YOUR_USERNAME", | ||
"password": "YOUR_PASSWORD", | ||
"location": "SOME_LOCATION", | ||
"gmapkey": "GOOGLE_MAPS_API_KEY", | ||
"max_steps": 5, | ||
"catch_pokemon": true, | ||
"forts": { | ||
"spin": true, | ||
"move_to_spin": false, | ||
"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, | ||
"action_wait_max": 4, | ||
"debug": false, | ||
"test": false, | ||
"health_record": true, | ||
"location_cache": true, | ||
"distance_unit": "km", | ||
"reconnecting_timeout": 15, | ||
"item_filter": { | ||
"1": { "keep" : 100 }, | ||
"101": { "keep" : 10 }, | ||
"102": { "keep" : 30 }, | ||
"103": { "keep" : 30 }, | ||
"201": { "keep" : 30 }, | ||
"701": { "keep" : 100 } | ||
}, | ||
"evolve_all": "NONE", | ||
"evolve_speed": 20, | ||
"evolve_cp_min": 300, | ||
"use_lucky_egg": false, | ||
"hatch_eggs": true, | ||
"longer_eggs_first": true, | ||
"evolve_captured": "NONE", | ||
"release_pokemon": true, | ||
"catch_randomize_reticle_factor": 1.0, | ||
"catch_randomize_spin_factor": 1.0, | ||
"catch": { | ||
"any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"}, | ||
"// Example of always catching Rattata:": {}, | ||
"// Rattata": { "always_catch" : true } | ||
}, | ||
"release": { | ||
"any": {"release_below_cp": 0, "release_below_iv": 0, "logic": "or"}, | ||
"// Example of always releasing Rattata:": {}, | ||
"// Rattata": {"always_release": true}, | ||
"// Example of keeping 3 stronger (based on CP) Pidgey:": {}, | ||
"// Pidgey": {"keep_best_cp": 3}, | ||
"// Example of keeping 2 stronger (based on IV) Zubat:": {}, | ||
"// Zubat": {"keep_best_iv": 2}, | ||
"// Also, it is working with any": {}, | ||
"// any": {"keep_best_iv": 3}, | ||
"// Example of keeping the 2 strongest (based on CP) and 3 best (based on IV) Zubat:": {}, | ||
"// Zubat": {"keep_best_cp": 2, "keep_best_iv": 3} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[ | ||
{"lng":8.043531775474547,"lat":52.27777834853098}, | ||
{"lng":8.045151829719543,"lat":52.27796214757581}, | ||
{"lng":8.045924305915833,"lat":52.27753218790187}, | ||
{"lng":8.045715093612671,"lat":52.27696437216979}, | ||
{"lng":8.044642210006714,"lat":52.27692826803333}, | ||
{"lng":8.043639063835144,"lat":52.27722694682294}, | ||
{"lng":8.043547868728638,"lat":52.27761095945195} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from spiral_navigator import SpiralNavigator | ||
from path_navigator import PathNavigator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import gpxpy | ||
import gpxpy.gpx | ||
import json | ||
import pokemongo_bot.logger as logger | ||
from pokemongo_bot.cell_workers.utils import distance, i2f, format_dist | ||
from pokemongo_bot.human_behaviour import sleep | ||
from pokemongo_bot.step_walker import StepWalker | ||
from pgoapi.utilities import f2i | ||
|
||
|
||
class PathNavigator(object): | ||
|
||
def __init__(self, bot): | ||
self.bot = bot | ||
self.api = bot.api | ||
self.config = bot.config | ||
self.ptr = 0 | ||
self.points = self.load_path() | ||
|
||
def load_path(self): | ||
if self.config.navigator_path_file == None: | ||
raise RuntimeError('You need to specify a path file (json or gpx)') | ||
|
||
if self.config.navigator_path_file.endswith('.json'): | ||
return self.load_json(self.config.navigator_path_file) | ||
elif self.config.navigator_path_file.endswith('.gpx'): | ||
return self.load_gpx(self.config.navigator_path_file) | ||
|
||
def load_json(self, file): | ||
with open(file) as data_file: | ||
return json.load(data_file) | ||
|
||
def load_gpx(self, file): | ||
gpx_file = open(file, 'r') | ||
gpx = gpxpy.parse(gpx_file) | ||
|
||
if len(gpx.tracks) == 0: | ||
raise RuntimeError('GPX file does not cotain a track') | ||
|
||
points = [] | ||
track = gpx.tracks[0] | ||
for segment in track.segments: | ||
for point in segment.points: | ||
points.append({"lat": point.latitude, "lng": point.longitude}) | ||
|
||
return points; | ||
|
||
def take_step(self): | ||
point = self.points[self.ptr] | ||
lat = float(point['lat']) | ||
lng = float(point['lng']) | ||
|
||
if self.config.walk > 0: | ||
step_walker = StepWalker( | ||
self.bot, | ||
self.config.walk, | ||
lat, | ||
lng | ||
) | ||
|
||
is_at_destination = False | ||
if step_walker.step(): | ||
is_at_destination = True | ||
|
||
else: | ||
self.api.set_position(lat, lng) | ||
|
||
dist = distance( | ||
self.api._position_lat, | ||
self.api._position_lng, | ||
lat, | ||
lng | ||
) | ||
|
||
if dist <= 1 or (self.config.walk > 0 and is_at_destination): | ||
if (self.ptr + 1) == len(self.points): | ||
self.ptr = 0 | ||
if self.config.navigator_path_mode == 'linear': | ||
self.points = list(reversed(self.points)) | ||
else: | ||
self.ptr += 1 | ||
|
||
return [lat, lng] |
8 changes: 4 additions & 4 deletions
8
pokemongo_bot/spiral_navigator.py → pokemongo_bot/navigators/spiral_navigator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ flask==0.11.1 | |
socketIO_client==0.7.0 | ||
eventlet==0.19.0 | ||
universal-analytics-python==0.2.4 | ||
gpxpy==1.1.1 |