Module edupage_api.subjects

Classes

class Subject (subject_id: int, name: str, short: str)
Expand source code
@dataclass
class Subject:
    subject_id: int
    name: str
    short: str

Subject(subject_id: int, name: str, short: str)

Class variables

var name : str
var short : str
var subject_id : int
class Subjects (edupage: EdupageModule)
Expand source code
class Subjects(Module):
    @ModuleHelper.logged_in
    def get_subjects(self) -> Optional[list]:
        subject_list = DbiHelper(self.edupage).fetch_subject_list()

        if subject_list is None:
            return None

        subjects = []

        for subject_id_str in subject_list:
            if not subject_id_str:
                continue

            subjects.append(
                Subject(
                    int(subject_id_str),
                    subject_list[subject_id_str]["name"],
                    subject_list[subject_id_str]["short"],
                )
            )

        return subjects

    def get_subject(self, subject_id: Union[int, str]) -> Optional[Subject]:
        try:
            subject_id = int(subject_id)
        except (ValueError, TypeError):
            return None

        return next(
            (
                subject
                for subject in self.get_subjects()
                if subject.subject_id == subject_id
            ),
            None,
        )

Ancestors

Methods

def get_subject(self, subject_id: int | str) ‑> Subject | None
Expand source code
def get_subject(self, subject_id: Union[int, str]) -> Optional[Subject]:
    try:
        subject_id = int(subject_id)
    except (ValueError, TypeError):
        return None

    return next(
        (
            subject
            for subject in self.get_subjects()
            if subject.subject_id == subject_id
        ),
        None,
    )
def get_subjects(self) ‑> list | None
Expand source code
@ModuleHelper.logged_in
def get_subjects(self) -> Optional[list]:
    subject_list = DbiHelper(self.edupage).fetch_subject_list()

    if subject_list is None:
        return None

    subjects = []

    for subject_id_str in subject_list:
        if not subject_id_str:
            continue

        subjects.append(
            Subject(
                int(subject_id_str),
                subject_list[subject_id_str]["name"],
                subject_list[subject_id_str]["short"],
            )
        )

    return subjects