Skip to content

Commit

Permalink
Merge pull request #253 from Skythrew/master
Browse files Browse the repository at this point in the history
Add basic report support
  • Loading branch information
bain3 authored Aug 3, 2023
2 parents d57fdeb + 7648d29 commit 8ee8b67
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/source/api/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,6 @@ from PRONOTE. It also includes a useful :class:`.Util` class.

.. autoclass:: Punishment
:members:

.. autoclass:: Report
:members:
95 changes: 94 additions & 1 deletion pronotepy/dataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"Menu",
"Punishment",
"Delay",
"Report",
)

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -318,7 +319,84 @@ def __init__(self, parsed_json: dict) -> None:
self.name: str = self._resolver(str, "L")
self.groups: bool = self._resolver(bool, "estServiceGroupe", default=False)

del self._resolver

class Report(Object):
"""Represents a student report. You shouldn't have to create this class manually.
Attributes:
subjects (List[ReportSubject]): the subjects that are present in the report
comments (List[str]): the global report comments
"""

class ReportSubject(Object):
"""
Represents a subject found in a report. You shouldn't have to create this class manually.
Attributes:
id (str): the id of the subject (used internally)
name (str): name of the subject
color (str): the color of the subject
comments (List[str]): the list of the subject's comments
class_average (Optional[str]): the average of the class
student_average (Optional[str]): the average of the student
min_average (Optional[str]): the lowest average of the class
max_average (Optional[str]): the highest average of the class
coefficient (Optional[str]): the coefficient of the subject
teachers (List[str]): the subject's teachers' names
"""

def __init__(self, parsed_json: dict) -> None:
super().__init__(parsed_json)

self.id: str = self._resolver(str, "N")
self.name: str = self._resolver(str, "L")

self.color: str = self._resolver(str, "couleur")
self.comments: List[str] = self._resolver(
lambda l: [c["L"] for c in l if "L" in c], "ListeAppreciations", "V"
)

def grade_or_none(grade: Any) -> Optional[str]:
return Util.grade_parse(grade) if grade else None

self.class_average: Optional[str] = self._resolver(
grade_or_none, "MoyenneClasse", "V", strict=False
)
self.student_average: Optional[str] = self._resolver(
grade_or_none, "MoyenneEleve", "V", strict=False
)
self.min_average: Optional[str] = self._resolver(
grade_or_none, "MoyenneInf", "V", strict=False
)
self.max_average: Optional[str] = self._resolver(
grade_or_none, "MoyenneSup", "V", strict=False
)
self.coefficient: Optional[str] = self._resolver(
str, "Coefficient", "V", strict=False
)
self.teachers: List[str] = self._resolver(
lambda l: [i["L"] for i in l], "ListeProfesseurs", "V", default=[]
)

del self._resolver

def __init__(self, parsed_json: dict) -> None:
super().__init__(parsed_json)

self.subjects: List[Report.ReportSubject] = self._resolver(
lambda l: [Report.ReportSubject(s) for s in l],
"ListeServices",
"V",
default=[],
)
self.comments: List[str] = self._resolver(
lambda l: [c["L"] for c in l if "L" in c],
"ObjetListeAppreciations",
"V",
"ListeAppreciations",
"V",
default=[],
)


class Absence(Object):
Expand Down Expand Up @@ -415,6 +493,21 @@ def __init__(self, client: ClientBase, json_dict: dict) -> None:

del self._resolver

@property
def report(self) -> Optional[Report]:
"""
Gets a report from a period.
Returns:
Optional[Report]:
When ``None``, then the report is not yet published or is unavailable for any other reason
"""
json_data = {"periode": {"G": 2, "N": self.id, "L": self.name}}
data = self._client.post("PageBulletins", 13, json_data)["donneesSec"][
"donnees"
]
return Report(data) if "Message" not in data else None

@property
def grades(self) -> List["Grade"]:
"""Get grades from the period."""
Expand Down
4 changes: 4 additions & 0 deletions pronotepy/test_pronotepy.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ def test_class_overall_average(self) -> None:
a = self.period.class_overall_average
self.assertTrue(type(a) is str or a is None)

def test_report(self) -> None:
report = self.period.report
self.assertTrue(report is None or isinstance(report, pronotepy.Report))


class TestInformation(unittest.TestCase):
def test_unread(self) -> None:
Expand Down

0 comments on commit 8ee8b67

Please sign in to comment.