Skip to content

Return the child's timetable from get_my_timetable() for parents - #129

Merged
ivanhrabcak merged 3 commits into
EdupageAPI:masterfrom
MilanPala:fix-parent-timetable
Oct 11, 2026
Merged

ivanhrabcak merged 3 commits into
EdupageAPI:masterfrom
MilanPala:fix-parent-timetable

Conversation

@MilanPala

@MilanPala MilanPala commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Same traceback as #81. With a parent account, get_my_timetable() fails in __get_date_plan:

curriculum_json = curriculum_response.text.split(response_start)[1].rsplit(
IndexError: list index out of range

A parent (Rodic-…) has no timetable of their own. Without a child selected, EduPage answers the loadData gcall with only:

JS:var gi…=document.getElementById('…').ASC_gjsc;window.location.reload();

so the Rodic-…", marker the code splits on isn't in the response. Calling switch_to_child() first works, because get_my_timetable() then goes through get_timetable(student, date).

Fix (WARNING: OUTDATED INFORMATION, read comment below)

  • In get_my_timetable(), a parent account with no selected child and exactly one child in data["parentStudentids"] uses that child, through the existing get_timetable(student, date) path. Nothing is switched on the server.
  • A parent with zero or several children gets a MissingDataException asking them to call switch_to_child() first.
  • __get_date_plan raises MissingDataException instead of IndexError when the response doesn't contain the expected marker.

Tests

New tests/test_timetable_parent.py: a parent with one child gets the child's timetable, a parent with zero, several or None children gets MissingDataException, and an unexpected response raises MissingDataException. The tests fail on master, and the suite passes. Also checked against a real one-child parent account: a school day returns 6 lessons.

Fixes #81

Co-Authored-By: Claude Code

Milan Pála and others added 3 commits October 11, 2026 13:32
…pageAPI#81)

A parent account has no timetable of its own, EduPage answers the
loadData request with a page reload, and get_my_timetable() failed with
IndexError. When no child is selected and the parent has exactly one
child, use that child's timetable. Otherwise raise MissingDataException
asking to call switch_to_child(), and raise it instead of IndexError
for any other unexpected response.

Co-Authored-By: Claude Code
@ivanhrabcak

Copy link
Copy Markdown
Member

I had a hard time deciding what to do here.

Auto-selecting the only child is convenient, but that only fixes get_my_timetable(). switch_to_child() changes the session on Edupage's side, which is why grades, notifications and the other methods work on the child's data afterwards. A parent with one child could get a timetable without switching, and then get_grades() would still run as the parent and fail.

I'd rather "create" a new (unwritten) rule for every method that is broken for parents: call switch_to_child() first.
I changed the behavior so it fits this rule:

A parent account with no selected child now gets MissingDataException: "A parent account has no timetable of its own, select a child with switch_to_child() first."

For a parent with one child, correct usage is:

from datetime import date
from edupage_api import Edupage

edupage = Edupage()
edupage.login("username", "password", "subdomain")

child_id = edupage.data["parentStudentids"][0]

edupage.switch_to_child(child_id)
timetable = edupage.get_my_timetable(date.today())

When writing the example, I realized there is no way to easily get a list of your own children (as a parent). That is what I'll try to handle next to improve the experience.

Thank you for your contribution!

@ivanhrabcak
ivanhrabcak merged commit e2947af into EdupageAPI:master Oct 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] list index problem in get_my_timetable()

2 participants