Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Updates To the fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
olijeffers0n committed Dec 2, 2023
1 parent 59e4bf4 commit 50a05c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion schedule/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__name__ = "MySchedule.py"
__version__ = "1.0.7"
__version__ = "1.0.8"

from .api import ScheduleAPI
29 changes: 15 additions & 14 deletions schedule/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ def generate_date(date_string: str) -> datetime:

@staticmethod
def time_from_number(number):
hours = str(number // 60)
minutes = str(number % 60)
return f"{number // 60}:{minutes if len(minutes) == 2 else minutes + '0'}"
return f"{hours if len(hours) == 2 else '0' + hours}:{minutes if len(minutes) == 2 else minutes + '0'}"

def _create_form(self):
data = self.session.get(
Expand Down Expand Up @@ -149,20 +150,27 @@ def login(self) -> None:
self.auth_token = self._create_session(create_form_html)
self._get_all_data()

def get_shifts_for_week(self, week_code: int) -> List[Shift]:
def get_shifts_for_date(self, date: datetime) -> List[Shift]:
"""
:param week_code: The week code to get the shifts for
:return: A list of shifts for the given week code
:param date: The date to get the shifts for
:return: A list of shifts for the given date
"""
shifts = []

if self.data is None:
raise Exception("You must login before you can get shifts")

self.session.get(
"https://mcduk.reflexisinc.co.uk/RWS4/ess/ess_emp_schedule.jsp?authToken="
+ self.auth_token
req = self.session.get(
f"https://mcduk.reflexisinc.co.uk/RWS4/ess/ess_emp_schedule.jsp?authToken={self.auth_token}&scheduleDate={date.strftime('%Y%m%d')}"
)

if req.status_code != 200:
raise Exception("Failed to get shifts")

data = str(req.content)
index = data.index("setGenShiftId")
week_code = int(data[index + 14: index + data[index:].index(")")])

req = self.session.get(
f"https://mcduk.reflexisinc.co.uk/RWS4/controller/ess/map/{self.data['storeId']}/"
f"{week_code}"
Expand Down Expand Up @@ -190,13 +198,6 @@ def get_shifts_for_week(self, week_code: int) -> List[Shift]:

return shifts

def get_shifts_for_date(self, date: datetime.date) -> List[Shift]:
"""
:param date: The date to get the shifts for
:return: A list of shifts for the given date
"""
return self.get_shifts_for_week(int(self.get_week_code_for_date(date)))

@staticmethod
def extract_time(cdata):
"""
Expand Down

0 comments on commit 50a05c4

Please sign in to comment.