Skip to content

Commit

Permalink
Wake up at location after sleep schedule (#4443)
Browse files Browse the repository at this point in the history
* Correct sort on keep best custom

* Add wake up at location in sleep schedule

* Update docs for sleep schedule

* final corrections for wake up at location in sleep schedule

* Do not use self.wake up at location without set up in config file

* Update (again?) the docs for randompause

* Include a mention of altitude in default config docs

* Update config.json.example with empty field for wake up at

* Repair config.example (a comma)
  • Loading branch information
supercourgette authored and solderzzc committed Aug 21, 2016
1 parent 6f9ae7d commit 3381add
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
3 changes: 2 additions & 1 deletion configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"time": "22:54",
"duration":"7:46",
"time_random_offset": "00:24",
"duration_random_offset": "00:43"
"duration_random_offset": "00:43",
"wake_up_at_location": ""
}
},
{
Expand Down
48 changes: 48 additions & 0 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -568,3 +568,51 @@ Available `items` :
```
2016-08-20 18:56:22,754 [UpdateLiveInventory] [INFO] [show_inventory] Items: 335/350 | Pokeballs: 8 | GreatBalls: 186 | UltraBalls: 0 | RazzBerries: 51 | LuckyEggs: 3
```
## Sleep Schedule Task

Pauses the execution of the bot every day for some time

Simulates the user going to sleep every day for some time, the sleep time and the duration is changed every day by a random offset defined in the config file.

- `time`: (HH:MM) local time that the bot should sleep
- `duration`: (HH:MM) the duration of sleep
- `time_random_offset`: (HH:MM) random offset of time that the sleep will start for this example the possible start time is 11:30-12:30
- `duration_random_offset`: (HH:MM) random offset of duration of sleep for this example the possible duration is 5:00-6:00
- `wake_up_at_location`: (lat, long | lat, long, alt | "") the location at which the bot wake up *Note that an empty string ("") will not change the location*.

###Example Config
```
{
"type": "SleepSchedule",
"config": {
"time": "12:00",
"duration":"5:30",
"time_random_offset": "00:30",
"duration_random_offset": "00:30"
"wake_up_at_location": "39.408692,149.595838,590.8"
}
}
```
## Random Pause

Pause the execution of the bot at a random time for a random time.

Simulates the random pause of the day (speaking to someone, getting into a store, ...) where the user stops the app. The interval between pauses and the duration of pause are configurable.

- `min_duration`: (HH:MM:SS) the minimum duration of each pause
- `max_duration`: (HH:MM:SS) the maximum duration of each pause
- `min_interval`: (HH:MM:SS) the minimum interval between each pause
- `max_interval`: (HH:MM:SS) the maximum interval between each pause

###Example Config
```
{
"type": "RandomPause",
"config": {
"min_duration": "00:00:10",
"max_duration": "00:10:00",
"min_interval": "00:10:00",
"max_interval": "02:00:00"
}
}
```
22 changes: 21 additions & 1 deletion pokemongo_bot/cell_workers/sleep_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SleepSchedule(BaseTask):
"duration":"5:30",
"time_random_offset": "00:30",
"duration_random_offset": "00:30"
"wake_up_at_location": ""
}
}
time: (HH:MM) local time that the bot should sleep
Expand All @@ -26,7 +27,8 @@ class SleepSchedule(BaseTask):
for this example the possible start time is 11:30-12:30
duration_random_offset: (HH:MM) random offset of duration of sleep
for this example the possible duration is 5:00-6:00
"""
wake_up_at_location: (lat, long | lat, long, alt | "") the location at which the bot wake up
*Note that an empty string ("") will not change the location*. """
SUPPORTED_TASK_API_VERSION = 1

LOG_INTERVAL_SECONDS = 600
Expand All @@ -42,6 +44,9 @@ def work(self):
if self._should_sleep_now():
self._sleep()
self._schedule_next_sleep()
wake_up_at_location = self.config.get("wake_up_at_location", "")
if wake_up_at_location:
self.bot.api.set_position(self.wake_up_at_location[0],self.wake_up_at_location[1],self.wake_up_at_location[2])
self.bot.login()

def _process_config(self):
Expand All @@ -60,6 +65,21 @@ def _process_config(self):
self.duration_random_offset = int(
timedelta(
hours=duration_random_offset.hour, minutes=duration_random_offset.minute).total_seconds())

wake_up_at_location = self.config.get("wake_up_at_location", "")
if wake_up_at_location:
try:
wake_up_at_location = wake_up_at_location.split(',',2)
lat=float(wake_up_at_location[0])
lng=float(wake_up_at_location[1])
if len(wake_up_at_location) == 3:
alt=float(wake_up_at_location[2])
else:
alt = uniform(self.bot.config.alt_min, self.bot.config.alt_max)
except ValueError:
raise ValueError('SleepSchedule wake_up_at_location, parsing error in location') #TODO there must be a more elegant way to do it...

self.wake_up_at_location = [lat, lng, alt]

def _schedule_next_sleep(self):
self._next_sleep = self._get_next_sleep_schedule()
Expand Down

0 comments on commit 3381add

Please sign in to comment.