Skip to content
Open
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
7 changes: 6 additions & 1 deletion edupage_api/parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class Parent(Module):
@ModuleHelper.logged_in
@ModuleHelper.is_parent
def switch_to_child(self, child: Union[EduAccount, int]):
params = {"studentid": child.person_id if type(child) == EduAccount else child}
child_id = child.person_id if isinstance(child, EduAccount) else child
params = {"studentid": child_id}

url = f"https://{self.edupage.subdomain}.edupage.org/login/switchchild"
response = self.edupage.session.get(url, params=params)
Expand All @@ -19,6 +20,8 @@ def switch_to_child(self, child: Union[EduAccount, int]):
f"{response.text}: Invalid child selected! (not your child?)"
)

self.edupage._selected_child_id = int(child_id)

@ModuleHelper.logged_in
@ModuleHelper.is_parent
def switch_to_parent(self):
Expand All @@ -32,3 +35,5 @@ def switch_to_parent(self):

if "EdupageLoginFailed" in response.url:
raise UnknownServerError()

self.edupage._selected_child_id = None
12 changes: 12 additions & 0 deletions edupage_api/timetables.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,18 @@ def __parse_timetable(self, plan):

@ModuleHelper.logged_in
def get_my_timetable(self, date: date) -> Optional[Timetable]:
selected_child_id = getattr(self.edupage, "_selected_child_id", None)

if selected_child_id is not None:
student = People(self.edupage).get_student(selected_child_id)

if student is None:
raise MissingDataException(
f"Selected child with ID {selected_child_id} was not found."
)

return self.get_timetable(student, date)

plan = self.__get_date_plan(date)
return self.__parse_timetable(plan)

Expand Down
22 changes: 22 additions & 0 deletions examples/timetables.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@
edupage.login_auto("Username (or e-mail)", "Password")

# My timetable
# Leave as None to keep the original get_my_timetable() behavior.
# Set a full student name to explicitly switch to a specific child.
student_name = None
# student_name = "Alžbeta Výborná"

if student_name is not None:
students = edupage.get_students() or []

student = next(
(student for student in students if student.name == student_name),
None,
)

if student is None:
available_students = [student.name for student in students]
raise RuntimeError(
f"Student {student_name!r} was not found. "
f"Available students: {available_students}"
)

edupage.switch_to_child(student)

date = datetime.date(2024, 6, 12)
timetable = edupage.get_my_timetable(date)

Expand Down