Skip to content

Commit

Permalink
SleepSchedule check if current sleep period is over
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Yao committed Aug 15, 2016
1 parent 603aca6 commit f0a2dc8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pokemongo_bot/cell_workers/sleep_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def initialize(self):
self._schedule_next_sleep()

def work(self):
if datetime.now() >= self._next_sleep:
if _should_sleep_now:
self._sleep()
self._schedule_next_sleep()
self.bot.login()
Expand Down Expand Up @@ -91,6 +91,16 @@ def _get_random_offset(self, max_offset):
offset = uniform(-max_offset, max_offset)
return int(offset)

def _should_sleep_now(self):
current_sleep = self._next_sleep -= timedelta(days=1)
current_duration = self._get_next_duration()
current_end = current_sleep += timedelta(hours = current_duration.hour, minutes = current_duration.minute)

if datetime.now() >= self._next_sleep:
return true
if datetime.now() <= current_end:
self._next_duration = (current_end - datetime.now()).total_seconds()

def _sleep(self):
sleep_to_go = self._next_duration
self.emit_event(
Expand Down

0 comments on commit f0a2dc8

Please sign in to comment.