Skip to content

Commit

Permalink
fix: add datetime calendar weeks
Browse files Browse the repository at this point in the history
  • Loading branch information
seblum committed Jan 21, 2024
1 parent e482eec commit 1260739
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-push-to-dockerhub_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: publish docker CD

env:
DOCKERREPO: seblum/octivbooker
TAG: v1.4.1
TAG: v1.4.2

on:
push:
Expand Down
33 changes: 10 additions & 23 deletions slotBooker/slotbooker/helper_functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from datetime import date

from datetime import date, timedelta

def get_xpath_booking_head() -> str:
"""Head of the XPath of the booking table page after log in
Expand Down Expand Up @@ -29,35 +28,23 @@ def get_xpath_login_password_head() -> str:
return "/html/body/div[1]/div[3]/div/div/div/div/div/div/form"


def get_day(days_before_bookable: int) -> tuple[str, bool, int]:
def get_day(days_before_bookable: int) -> tuple[date, int]:
"""Checks and selects which day will be selected,
based on how many days from today shall be selected
Args:
days_before_bookable (int): Number of days to go in the future
Returns:
tuple[str, bool]: weekday to be selected, True if weekday is in the next week
tuple[date, int]: future day to be selected, nr of different calendar weeks
"""
week_days = (
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday",
)
today = date.today().weekday()
future_day = today + days_before_bookable
if future_day < 7:
return week_days[future_day], False, 0
else:
nr_weeks = int(round(days_before_bookable / 7,0))
future_day = future_day - 7
if future_day == 7:
future_day = 0
return week_days[future_day], True, nr_weeks
today = date.today()
future_date = today + timedelta(days=days_before_bookable)
today_calendar_week = today.isocalendar().week
future_calendar_week = future_date.isocalendar().week
diff_week = future_calendar_week-today_calendar_week

return future_date, diff_week



Expand Down
13 changes: 6 additions & 7 deletions slotBooker/slotbooker/ui_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,25 +121,24 @@ def switch_day(self) -> str:
Raises:
TimeoutException: If the day switch process times out.
"""
day, next_week, nr_weeks = get_day(self.days_before_bookable)
if next_week:
while nr_weeks > 0:
future_date, diff_week = get_day(self.days_before_bookable)
day = future_date.strftime("%A")
if diff_week > 0:
while diff_week > 0:
WebDriverWait(self.driver, 20).until(
EC.element_to_be_clickable(
(By.XPATH, f"{get_xpath_booking_head()}[3]/div[9]/div/div/i")
)
).click()
logging.info("| switched to following week")
nr_weeks -= 1
diff_week -= 1

day_button = get_day_button(day)
WebDriverWait(self.driver, 20).until(
EC.element_to_be_clickable((By.XPATH, day_button))
).click()

future_date = datetime.today() + timedelta(days=self.days_before_bookable)
future_date_formatted = future_date.date().strftime("%d-%m-%Y")
logging.info(f"| switched to day: {day}, {future_date_formatted}")
logging.info(f"| switched to day: {day}, {future_date}")
self.day = day

def book_class(self, class_dict: dict, booking_action: bool = True) -> None:
Expand Down

0 comments on commit 1260739

Please sign in to comment.