Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate similar meaning configuration keys properly inside another key #1590

Merged
merged 8 commits into from
Jul 29, 2016
10 changes: 5 additions & 5 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
"gmapkey": "GOOGLE_MAPS_API_KEY",
"max_steps": 5,
"catch_pokemon": true,
"forts": {
"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 @@ -33,10 +37,6 @@
"longer_eggs_first": true,
"evolve_captured": false,
"release_pokemon": true,
"spin_forts": {
"avoid_circles": false,
"max_circle_size": 10
},
"catch": {
"any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"},
"// Example of always catching Rattata:": {},
Expand Down
10 changes: 5 additions & 5 deletions configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"gmapkey": "GOOGLE_MAPS_API_KEY",
"max_steps": 5,
"catch_pokemon": true,
"spin_forts": true,
"forts": {
"spin": true,
"avoid_circles": true,
"max_circle_size": 50
},
"walk": 4.16,
"action_wait_min": 1,
"action_wait_max": 4,
Expand All @@ -32,10 +36,6 @@
"longer_eggs_first": true,
"evolve_captured": false,
"release_pokemon": true,
"spin_forts": {
"avoid_circles": false,
"max_circle_size": 10
},
"catch": {
"any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or" },

Expand Down
19 changes: 14 additions & 5 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,11 @@ def init_config():
add_config(
parser,
load,
long_flag="--spin_forts",
long_flag="--spin",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't this be --forts_spin based on your logic below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hum, let me try something

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheSavior if in add_config I rewrite the long_flag like this:

if embedded_in:
    long_flag = "{}_{}".format(embedded_in, long_flag)

What you think

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we scrap all of our cli arguments and instead dynamically let people override anything in the config.json, supporting deeply nested objects like so:

--username my_username --forts.avoid_circles false --location_cache true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just go for long_flag="--forts_spin" for now.

rewriting all cli arguments management is a little out of this PR scope no ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, out of scope. I've been teasing @douglascamata about this change for a few days. It was a proposal from a few days ago that solved some very specific problems that we just never seemed to implement: #573 (comment)

help="Enable Spinning Pokestops",
type=bool,
default=True
default=True,
embedded_in='forts'
)
add_config(
parser,
Expand Down Expand Up @@ -313,7 +314,8 @@ def init_config():
long_flag="--avoid_circles",
help="Avoids circles (pokestops) of the max size set in max_circle_size flag",
type=bool,
default=False
default=False,
embedded_in='forts'
)
add_config(
parser,
Expand All @@ -322,7 +324,8 @@ def init_config():
long_flag="--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,
embedded_in='forts'
)

# Start to parse other attrs
Expand Down Expand Up @@ -364,13 +367,19 @@ 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(',')]

import pdb; pdb.set_trace()
return config

def add_config(parser, json_config, short_flag=None, long_flag=None, **kwargs):
def add_config(parser, json_config, short_flag=None, long_flag=None, embedded_in=None, **kwargs):
if not long_flag:
raise Exception('add_config calls requires long_flag parameter!')
if 'default' in kwargs:
attribute_name = long_flag.split('--')[1]
if embedded_in:
json_config = json_config.get(embedded_in, None)
if not json_config:
raise Exception('Container "{}" for key "{}" didnt found!'.format(embedded_in, attribute_name))
kwargs['dest'] = "{}_{}".format(embedded_in, attribute_name)
kwargs['default'] = json_config.get(attribute_name, kwargs['default'])
if short_flag:
args = (short_flag, long_flag)
Expand Down
3 changes: 1 addition & 2 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ def __init__(self, config):
self.metrics = Metrics(self)
self.latest_inventory = None
self.cell = None
self.recent_forts = [None] * config.max_circle_size
self.recent_forts = [None] * config.forts_max_circle_size
self.tick_count = 0


def start(self):
self._setup_logging()
self._setup_api()
Expand Down
2 changes: 1 addition & 1 deletion pokemongo_bot/cell_workers/spin_nearest_fort_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def should_run(self):

enough_space = self.bot.get_inventory_count('item') < self.bot._player['max_item_storage'] - number_of_things_gained_by_stop

return self.config.spin_forts and enough_space
return self.config.forts_spin and enough_space

def get_nearest_fort(self):
forts = self.bot.get_forts()
Expand Down