Skip to content

Commit

Permalink
Merge branch 'dev' into feature/docker-compose
Browse files Browse the repository at this point in the history
* dev: (43 commits)
  Display Fort Name instead of Fort ID in Log (PokemonGoF#1801)
  add a flag to enable user to choose if he wants to walk to spin forts (PokemonGoF#1772)
  [FIX] use_lucky_egg (PokemonGoF#1774)
  Prevent crash checking session (PokemonGoF#1754)
  * Always report session summary even on crash (PokemonGoF#1759)
  Don't try to release pokemons in forts (PokemonGoF#1751)
  Creating an instance of the workers only on startup (PokemonGoF#1750)
  No longer caching things on the worker. Pulling straight from the bot instance (PokemonGoF#1747)
  fixing wrong import
  Show Pokestop names (PokemonGoF#1671)
  adding a duplicate of SeenFortWorker before MoveToFortWorker
  Improve docker usage; use docker-compose for starting the PokemonGo-Bot ecosystem (PokemonGoF#1669)
  SoftBan Worker (PokemonGoF#1724)
  Huge clean-up: PEP8, sort imports, remove deprecated and unused imports (PokemonGoF#1697)
  Update config.json.pokemon.example (PokemonGoF#1711)
  feat: show xp after catching pokemons (PokemonGoF#1700)
  Revert "Making the SpiralNavigator a worker" (PokemonGoF#1698)
  fixes Polyline class to handle a case in which google is returning only one point (PokemonGoF#1674)
  Making the SpiralNavigator a worker (PokemonGoF#1683)
  Fix transfer worker not triggered for last pokemon (PokemonGoF#1664)
  ...
  • Loading branch information
Ihor Harahatyi committed Jul 30, 2016
2 parents 233d4bb + 2f277fd commit 51a93d5
Show file tree
Hide file tree
Showing 42 changed files with 761 additions and 544 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.git*
configs/config.json
**/*config.json
**/*userdata.js
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@
* SpaceWhale
* klingan
* reddivision
* kbinani
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
FROM python:2.7-onbuild

ARG timezone=Etc/UTC
RUN echo $timezone > /etc/timezone \
&& ln -sfn /usr/share/zoneinfo/$timezone /etc/localtime \
&& dpkg-reconfigure -f noninteractive tzdata

ADD requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ This bot takes a strong stance against automating gym battles. Botting gyms will
All information on [Getting Started](https://github.com/PokemonGoF/PokemonGo-Bot/wiki/Getting-Started) is available in the [Wiki](https://github.com/PokemonGoF/PokemonGo-Bot/wiki/)!
- __Installation__
- [Requirements] (https://github.com/PokemonGoF/PokemonGo-Bot/wiki/Installation#requirements-click-each-one-for-install-guide)
- [How to run with Docker](https://github.com/PokemonGoF/PokemonGo-Bot/wiki/Installation#how-to-run-with-docker)
- [How to run with Docker](https://github.com/PokemonGoF/PokemonGo-Bot/wiki/How-to-run-with-Docker)
- [Linux] (https://github.com/PokemonGoF/PokemonGo-Bot/wiki/Installation#installation-linux)
- [Mac] (https://github.com/PokemonGoF/PokemonGo-Bot/wiki/Installation#installation-mac)
- [Windows] (https://github.com/PokemonGoF/PokemonGo-Bot/wiki/Installation#installation-windows)
Expand Down
15 changes: 9 additions & 6 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
"gmapkey": "GOOGLE_MAPS_API_KEY",
"max_steps": 5,
"catch_pokemon": true,
"forts": {
"spin": true,
"move_to_spin": true,
"avoid_circles": true,
"max_circle_size": 50
},
"websocket_server": false,
"spin_forts": true,
"walk": 4.16,
"action_wait_min": 1,
"action_wait_max": 4,
Expand All @@ -31,12 +36,10 @@
"use_lucky_egg": false,
"hatch_eggs": true,
"longer_eggs_first": true,
"evolve_captured": false,
"evolve_captured": "NONE",
"release_pokemon": true,
"spin_forts": {
"avoid_circles": false,
"max_circle_size": 10
},
"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:": {},
Expand Down
18 changes: 12 additions & 6 deletions configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
"gmapkey": "GOOGLE_MAPS_API_KEY",
"max_steps": 5,
"catch_pokemon": true,
"spin_forts": true,
"forts": {
"spin": true,
"move_to_spin": true,
"avoid_circles": true,
"max_circle_size": 50
},
"websocket_server": false,
"walk": 4.16,
"action_wait_min": 1,
"action_wait_max": 4,
Expand All @@ -15,6 +21,7 @@
"health_record": true,
"location_cache": true,
"distance_unit": "km",
"reconnecting_timeout": 15,
"item_filter": {
"1": { "keep" : 50 },
"2": { "keep" : 50 },
Expand All @@ -27,15 +34,14 @@
},
"evolve_all": "NONE",
"evolve_speed": 20,
"evolve_cp_min": 300,
"use_lucky_egg": false,
"hatch_eggs": true,
"longer_eggs_first": true,
"evolve_captured": false,
"evolve_captured": "NONE",
"release_pokemon": true,
"spin_forts": {
"avoid_circles": false,
"max_circle_size": 10
},
"catch_randomize_reticle_factor": 1.0,
"catch_randomize_spin_factor": 1.0,
"catch": {
"any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or" },

Expand Down
141 changes: 108 additions & 33 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,32 +70,37 @@ def main():
except KeyboardInterrupt:
logger.log('Exiting PokemonGo Bot', 'red')
finished = True
if bot.metrics.start_time is None:
return # Bot didn't actually start, no metrics to show.

metrics = bot.metrics
metrics.capture_stats()
logger.log('')
logger.log('Ran for {}'.format(metrics.runtime()), 'cyan')
logger.log('Total XP Earned: {} Average: {:.2f}/h'.format(metrics.xp_earned(), metrics.xp_per_hour()), 'cyan')
logger.log('Travelled {:.2f}km'.format(metrics.distance_travelled()), 'cyan')
logger.log('Visited {} stops'.format(metrics.visits['latest'] - metrics.visits['start']), 'cyan')
logger.log('Encountered {} pokemon, {} caught, {} released, {} evolved, {} never seen before'
.format(metrics.num_encounters(), metrics.num_captures(), metrics.releases,
metrics.num_evolutions(), metrics.num_new_mons()), 'cyan')
logger.log('Threw {} pokeball{}'.format(metrics.num_throws(), '' if metrics.num_throws() == 1 else 's'),
'cyan')
logger.log('Earned {} Stardust'.format(metrics.earned_dust()), 'cyan')
logger.log('')
if metrics.highest_cp is not None:
logger.log('Highest CP Pokemon: {}'.format(metrics.highest_cp['desc']), 'cyan')
if metrics.most_perfect is not None:
logger.log('Most Perfect Pokemon: {}'.format(metrics.most_perfect['desc']), 'cyan')


report_summary(bot)
except NotLoggedInException:
logger.log('[x] Error while connecting to the server, please wait %s minutes' % config.reconnecting_timeout, 'red')
time.sleep(config.reconnecting_timeout * 60)
except:
# always report session summary and then raise exception
report_summary(bot)
raise

def report_summary(bot):
if bot.metrics.start_time is None:
return # Bot didn't actually start, no metrics to show.

metrics = bot.metrics
metrics.capture_stats()
logger.log('')
logger.log('Ran for {}'.format(metrics.runtime()), 'cyan')
logger.log('Total XP Earned: {} Average: {:.2f}/h'.format(metrics.xp_earned(), metrics.xp_per_hour()), 'cyan')
logger.log('Travelled {:.2f}km'.format(metrics.distance_travelled()), 'cyan')
logger.log('Visited {} stops'.format(metrics.visits['latest'] - metrics.visits['start']), 'cyan')
logger.log('Encountered {} pokemon, {} caught, {} released, {} evolved, {} never seen before'
.format(metrics.num_encounters(), metrics.num_captures(), metrics.releases,
metrics.num_evolutions(), metrics.num_new_mons()), 'cyan')
logger.log('Threw {} pokeball{}'.format(metrics.num_throws(), '' if metrics.num_throws() == 1 else 's'),
'cyan')
logger.log('Earned {} Stardust'.format(metrics.earned_dust()), 'cyan')
logger.log('')
if metrics.highest_cp is not None:
logger.log('Highest CP Pokemon: {}'.format(metrics.highest_cp['desc']), 'cyan')
if metrics.most_perfect is not None:
logger.log('Most Perfect Pokemon: {}'.format(metrics.most_perfect['desc']), 'cyan')

def init_config():
parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -182,10 +187,10 @@ def init_config():
add_config(
parser,
load,
long_flag="--spin_forts",
long_flag="--forts.spin",
help="Enable Spinning Pokestops",
type=bool,
default=True
default=True,
)
add_config(
parser,
Expand Down Expand Up @@ -275,9 +280,9 @@ def init_config():
load,
short_flag="-ec",
long_flag="--evolve_captured",
help="(Ad-hoc mode) Bot will attempt to evolve all the pokemon captured!",
type=bool,
default=False
help="(Ad-hoc mode) Pass \"all\" or a list of pokemon to evolve (e.g., \"Pidgey,Weedle,Caterpie\"). Bot will attempt to evolve all the pokemon captured!",
type=str,
default=[]
)
add_config(
parser,
Expand All @@ -297,6 +302,15 @@ def init_config():
type=float,
default=15.0
)
add_config(
parser,
load,
short_flag="-bf",
long_flag="--softban_fix",
help="Fix softban automatically",
type=bool,
default=False
)
add_config(
parser,
load,
Expand All @@ -310,19 +324,44 @@ def init_config():
parser,
load,
short_flag="-ac",
long_flag="--avoid_circles",
long_flag="--forts.avoid_circles",
help="Avoids circles (pokestops) of the max size set in max_circle_size flag",
type=bool,
default=False
default=False,
)
add_config(
parser,
load,
short_flag="-mcs",
long_flag="--max_circle_size",
long_flag="--forts.max_circle_size",
help="If avoid_circles flag is set, this flag specifies the maximum size of circles (pokestops) avoided",
type=int,
default=10
default=10,
)
add_config(
parser,
load,
short_flag="-mts",
long_flag="--forts.move_to_spin",
help="Moves to forts nearby ",
type=bool,
default=True
)
add_config(
parser,
load,
long_flag="--catch_randomize_reticle_factor",
help="Randomize factor for pokeball throwing accuracy (DEFAULT 1.0 means no randomize: always 'Excellent' throw. 0.0 randomizes between normal and 'Excellent' throw)",
type=float,
default=1.0
)
add_config(
parser,
load,
long_flag="--catch_randomize_spin_factor",
help="Randomize factor for pokeball curve throwing (DEFAULT 1.0 means no randomize: always perfect 'Super Spin' curve ball. 0.0 randomizes between normal and 'Super Spin' curve ball)",
type=float,
default=1.0
)

# Start to parse other attrs
Expand Down Expand Up @@ -350,10 +389,25 @@ def init_config():
' Set these to true or false and remove "mode" from your configuration')
return None

if (config.evolve_captured
and (not isinstance(config.evolve_captured, str)
or str(config.evolve_captured).lower() in ["true", "false"])):
parser.error('"evolve_captured" should be list of pokemons: use "all" or "none" to match all ' +
'or none of the pokemons, or use a comma separated list such as "Pidgey,Weedle,Caterpie"')
return None

if not (config.location or config.location_cache):
parser.error("Needs either --use-location-cache or --location.")
return None

if config.catch_randomize_reticle_factor < 0 or 1 < config.catch_randomize_reticle_factor:
parser.error("--catch_randomize_reticle_factor is out of range! (should be 0 <= catch_randomize_reticle_factor <= 1)")
return None

if config.catch_randomize_spin_factor < 0 or 1 < config.catch_randomize_spin_factor:
parser.error("--catch_randomize_spin_factor is out of range! (should be 0 <= catch_randomize_spin_factor <= 1)")
return None

# create web dir if not exists
try:
os.makedirs(web_dir)
Expand All @@ -363,21 +417,42 @@ def init_config():

if config.evolve_all and isinstance(config.evolve_all, str):
config.evolve_all = [str(pokemon_name) for pokemon_name in config.evolve_all.split(',')]
if config.evolve_captured and isinstance(config.evolve_captured, str):
config.evolve_captured = [str(pokemon_name) for pokemon_name in config.evolve_captured.split(',')]

fix_nested_config(config)
return config

def add_config(parser, json_config, short_flag=None, long_flag=None, **kwargs):
if not long_flag:
raise Exception('add_config calls requires long_flag parameter!')

full_attribute_path = long_flag.split('--')[1]
attribute_name = full_attribute_path.split('.')[-1]

if '.' in full_attribute_path: # embedded config!
embedded_in = full_attribute_path.split('.')[0: -1]
for level in embedded_in:
json_config = json_config.get(level, {})

if 'default' in kwargs:
attribute_name = long_flag.split('--')[1]
kwargs['default'] = json_config.get(attribute_name, kwargs['default'])
if short_flag:
args = (short_flag, long_flag)
else:
args = (long_flag,)
parser.add_argument(*args, **kwargs)


def fix_nested_config(config):
config_dict = config.__dict__

for key, value in config_dict.iteritems():
if '.' in key:
new_key = key.replace('.', '_')
config_dict[new_key] = value
del config_dict[key]

def parse_unicode_str(string):
try:
return string.decode('utf8')
Expand Down
Loading

0 comments on commit 51a93d5

Please sign in to comment.