From 1356711d30c0b412e3d959e89fe05a6580b871d6 Mon Sep 17 00:00:00 2001 From: Sebastian Blum Date: Fri, 3 Nov 2023 17:48:18 +0100 Subject: [PATCH] set execution time to later step --- .../build-and-push-to-dockerhub_version.yml | 2 +- slotBooker/poetry.Dockerfile | 2 +- slotBooker/pyproject.toml | 2 +- slotBooker/slotbooker/booker.py | 6 +++--- slotBooker/slotbooker/ui_interaction.py | 15 +++++++++------ 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-and-push-to-dockerhub_version.yml b/.github/workflows/build-and-push-to-dockerhub_version.yml index 5012704..c4deea0 100644 --- a/.github/workflows/build-and-push-to-dockerhub_version.yml +++ b/.github/workflows/build-and-push-to-dockerhub_version.yml @@ -2,7 +2,7 @@ name: publish docker CD env: DOCKERREPO: seblum/octivbooker - TAG: v1.2.2 + TAG: v1.3.0 on: push: diff --git a/slotBooker/poetry.Dockerfile b/slotBooker/poetry.Dockerfile index 3de2d7e..a4861a4 100644 --- a/slotBooker/poetry.Dockerfile +++ b/slotBooker/poetry.Dockerfile @@ -19,7 +19,7 @@ RUN apt-get install -yqq unzip # https://googlechromelabs.github.io/chrome-for-testing/#stable ENV ChromedriverVersion="119.0.6045.105" # $ChromedriverVersion -RUN wget -O /tmp/chromedriver.zip https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/119.0.6045.105/linux64/chromedriver-linux64.zip +RUN wget -O /tmp/chromedriver.zip https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/$ChromedriverVersion/linux64/chromedriver-linux64.zip RUN unzip /tmp/chromedriver.zip chromedriver-linux64/chromedriver -d /usr/local/bin/ # set display port to avoid crash diff --git a/slotBooker/pyproject.toml b/slotBooker/pyproject.toml index bb63d2d..d436c02 100644 --- a/slotBooker/pyproject.toml +++ b/slotBooker/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "slotBooker" -version = "1.2.2" +version = "1.3.0" description = "" authors = ["Sebastian Blum "] diff --git a/slotBooker/slotbooker/booker.py b/slotBooker/slotbooker/booker.py index 8550dbb..6230709 100644 --- a/slotBooker/slotbooker/booker.py +++ b/slotBooker/slotbooker/booker.py @@ -81,15 +81,15 @@ def main(retry: int = 3): ) close_driver(driver) - logging.info(f"OctivBooker succeeded | try: {count+1}") + logging.info(f"[{count+1}] OctivBooker succeeded") count = 3 except SessionNotCreatedException: - logging.info(f"OctivBooker failed | TRY: {count+1}") + logging.info(f"[{count+1}] OctivBooker failed") logging.info(f"! SessionNotCreatedException") count += 1 continue except NoSuchDriverException: - logging.info(f"OctivBooker failed | TRY: {count+1}") + logging.info(f"[{count+1}] OctivBooker failed") logging.info(f"! NoSuchDriverException") count += 1 continue diff --git a/slotBooker/slotbooker/ui_interaction.py b/slotBooker/slotbooker/ui_interaction.py index e5430f6..de6cd6a 100644 --- a/slotBooker/slotbooker/ui_interaction.py +++ b/slotBooker/slotbooker/ui_interaction.py @@ -259,7 +259,14 @@ def __click_book_button(xpath_button_book: str) -> None: """ # Use execute_script() when another element is covering the element to be clicked element = self.driver.find_element(By.XPATH, xpath_button_book) - self.driver.execute_script("arguments[0].click();", element) + + while True: + if datetime.now().time().strftime("%H:%M:%S") >= self.execution_booking_time: + logging.info(f"| Executed at {datetime.now().time()}") + self.driver.execute_script("arguments[0].click();", element) + break + + def __book_class_slot(button_xpath: str) -> bool: """ @@ -276,11 +283,7 @@ def __book_class_slot(button_xpath: str) -> bool: """ logging.info(f"| Booking {class_slot} at {time_slot}") - while True: - if datetime.now().time().strftime("%H:%M:%S") >= self.execution_booking_time: - logging.info(f"| Executed at {datetime.now().time()}") - __click_book_button(xpath_button_book=button_xpath) - break + __click_book_button(xpath_button_book=button_xpath) # Check whether alert appears alert_obj = alert_is_present(self.driver)