Skip to content

Commit

Permalink
Task EvolvePokemon should give us a status updates so we know it is w…
Browse files Browse the repository at this point in the history
…orking
  • Loading branch information
ch1ago committed Sep 26, 2016
1 parent 2fa4fda commit c8036a4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"type": "EvolvePokemon",
"config": {
"enabled": false,
"interval": 120,
"log_interval": 120,

"// evolve only pidgey and drowzee": "",
"// evolve_list": "pidgey, drowzee",
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ The behaviors of the bot are configured via the `tasks` key in the `config.json`
* EvolvePokemon
* `enable`: Disable or enable this task.
* `evolve_all`: Default `NONE` | Depreciated. Please use evolve_list and donot_evolve_list
* `interval`: `Default: 120`. Time (in seconds) to periodically check if you have enough pokemon to evolve (more than `min_pokemon_to_be_evolved`)
* `log_interval`: `Default: 120`. Time (in seconds) to periodically print how far you are from having enough pokemon to evolve (more than `min_pokemon_to_be_evolved`)
* `evolve_list`: Default `all` | Set to all, or specifiy different pokemon seperated by a comma
* `donot_evolve_list`: Default `none` | Pokemon seperated by comma, will be ignored from evolve_list
* `min_evolve_speed`: Default `25` | Minimum seconds to wait between each evolution
Expand Down
37 changes: 18 additions & 19 deletions pokemongo_bot/cell_workers/evolve_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def __init__(self, bot, config):

def initialize(self):
self.start_time = 0
self.next_update = None
self.interval = self.config.get('interval', 120)
self.next_log_update = None
self.log_interval = self.config.get('log_interval', 120)
self.evolve_list = self.config.get('evolve_list', [])
self.donot_evolve_list = self.config.get('donot_evolve_list', [])
self.min_evolve_speed = self.config.get('min_evolve_speed', 25)
Expand Down Expand Up @@ -57,9 +57,6 @@ def work(self):
if not self._should_run():
return

self._compute_next_update()

result_message = ""
filtered_list, filtered_dict = self._sort_and_filter()

pokemon_to_be_evolved = 0
Expand All @@ -70,7 +67,7 @@ def work(self):
candy = inventory.candies().get(pokemon.pokemon_id)
pokemon_to_be_evolved = pokemon_to_be_evolved + min(candy.quantity / (pokemon.evolution_cost - 1), filtered_dict[pokemon.pokemon_id])

self._print_check(pokemon_to_be_evolved, self.min_pokemon_to_be_evolved)
self._log_interval_if_should(pokemon_to_be_evolved, self.min_pokemon_to_be_evolved)

has_minimum_to_evolve = pokemon_to_be_evolved >= self.min_pokemon_to_be_evolved
if has_minimum_to_evolve:
Expand All @@ -81,23 +78,25 @@ def work(self):
if pokemon.can_evolve_now():
self._execute_pokemon_evolve(pokemon, cache)

def _print_check(self, has, needs):
self.emit_event(
'pokemon_evolve_check',
formatted='Evolvable: {has}/{need}',
data={
'has': has,
'needs': needs
}
)
def _log_interval_if_should(self, has, needs):
self._compute_next_log_update()
if self._should_log_update:
self.emit_event(
'pokemon_evolve_check',
formatted='Evolvable: {has}/{need}',
data={'has': has, 'needs': needs}
)

def _compute_next_log_update(self):
self.next_log_update = datetime.now() + timedelta(seconds=self.log_interval)

def _should_log_update(self):
return self.next_log_update is None or datetime.now() >= self.next_log_update

def _should_run(self):
if not self.evolve_list or self.evolve_list[0] == 'none':
return False
return self.next_update is None or datetime.now() >= self.next_update

def _compute_next_update(self):
self.next_update = datetime.now() + timedelta(seconds=self.interval)
return True

def _use_lucky_egg(self):
using_lucky_egg = time.time() - self.start_time < 1800
Expand Down

0 comments on commit c8036a4

Please sign in to comment.