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

Add option to set upper limit of time spent in waiting room #66

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions impf/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from impf.api import API
from impf.constructors import browser_options, format_appointments
from impf.decorators import shadow_ban, control_errors
from impf.exceptions import ImpfbotTimeoutError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -195,8 +196,15 @@ def main_page(self) -> None:

def waiting_room(self):
if not self.in_waiting_room: return
self.logger.info('Taking a seat in the waiting room (very german)')
while self.in_waiting_room: sleep(5)
self.logger.info('Taking a seat in the waiting room (very German)')
time_spent_in_waiting_room = 0
while self.in_waiting_room:
if time_spent_in_waiting_room > settings.WAIT_WAITING_ROOM:
raise ImpfbotTimeoutError(f'Maximum time in waiting room ({settings.WAIT_WAITING_ROOM} s) exceeded')
sleep_time = 5
sleep(sleep_time)
time_spent_in_waiting_room += sleep_time

self.logger.info('No longer in waiting room!')

@shadow_ban
Expand Down
4 changes: 3 additions & 1 deletion impf/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from selenium.common.exceptions import StaleElementReferenceException, WebDriverException

import settings
from impf.exceptions import AdvancedSessionCache, AlertError
from impf.exceptions import AdvancedSessionCache, AlertError, ImpfbotTimeoutError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -76,6 +76,8 @@ def func(self, *args, **kwargs):
'ability to interact before attempting to revover automatically...')
sleep(120)
return self.control_assert()
except ImpfbotTimeoutError as e:
self.logger.info(f'ImpfbotTimeoutError: {str(e)}')
except SystemExit:
self.logger.warning('Exiting...')
except:
Expand Down
5 changes: 5 additions & 0 deletions impf/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ def __repr__(self):

def __str__(self):
return f'[{self.code}] {self.message}'


class ImpfbotTimeoutError(Exception):
""" Custom timeout of impfbot was triggered """
pass
4 changes: 4 additions & 0 deletions settings.sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
# Seconds to wait before rechecking available appointments.
# Only relevant if RESCAN_APPOINTMENT is set to True
WAIT_RESCAN_APPOINTMENTS: int = 60*2 # 2 Min
# Seconds to wait in waiting room before skipping the current location
# Normally, the waiting room should disappear quickly by itself but in some
# cases a longer wait in there can happen
WAIT_WAITING_ROOM: int = 60*10 # 10 Min


# > Basic Features
Expand Down