Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⌚ Add delays #198

Merged
merged 3 commits into from
Jan 11, 2023
Merged
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
3 changes: 3 additions & 0 deletions docs/source/api/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ from PRONOTE. It also includes a useful :class:`.Util` class.
.. autoclass:: Absence
:members:

.. autoclass:: Delay
:members:

.. autoclass:: Period
:members:

Expand Down
47 changes: 46 additions & 1 deletion pronotepy/dataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,36 @@ def __init__(self, json_dict: dict) -> None:
del self._resolver


class Delay(Object):
"""
Represents a delay with a given period. You shouldn't have to create this class manually.

Attributes:
id (str): the id of the delay (used internally)
date (datetime.datetime): date of the delay
minutes (str): the number of minutes missed
justified (bool): is the delay justified
justification (str): the justification for the delay
reasons (List[str]): The reason(s) for the delay
"""

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

self.id: str = self._resolver(str, "N")
self.date: datetime.datetime = self._resolver(Util.datetime_parse, "date", "V")
self.minutes: int = self._resolver(int, "duree", default=0)
self.justified: bool = self._resolver(bool, "justifie", default=False)
self.justification: Optional[str] = self._resolver(
str, "justification", strict=False
)
self.reasons: List[str] = self._resolver(
lambda l: [i["L"] for i in l], "listeMotifs", "V", default=[]
)

del self._resolver


class Period(Object):
"""
Represents a period of the school year. You shouldn't have to create this class manually.
Expand Down Expand Up @@ -445,6 +475,21 @@ def absences(self) -> List[Absence]:
absences = response["donneesSec"]["donnees"]["listeAbsences"]["V"]
return [Absence(a) for a in absences if a["G"] == 13]

@property
def delays(self) -> List[Delay]:
"""
All delays from this period
"""
json_data = {
"periode": {"N": self.id, "L": self.name, "G": 2},
"DateDebut": {"_T": 7, "V": self.start.strftime("%d/%m/%Y %H:%M:%S")},
"DateFin": {"_T": 7, "V": self.end.strftime("%d/%m/%Y %H:%M:%S")},
}

response = self._client.post("PagePresence", 19, json_data)
delays = response["donneesSec"]["donnees"]["listeAbsences"]["V"]
return [Delay(a) for a in delays if a["G"] == 14]

@property
def punishments(self) -> List[Punishment]:
"""
Expand Down Expand Up @@ -667,11 +712,11 @@ class Lesson(Object):
classrooms (Optional[List[str]]): name of the classrooms
canceled (bool): if the lesson is canceled
status (Optional[str]): status of the lesson
memo (Optional[str]): memo of the lesson
background_color (Optional[str]): background color of the lesson
outing (bool): if it is a pedagogical outing
start (datetime.datetime): starting time of the lesson
end (datetime.datetime): end of the lesson
memo (Optional[str]): memo of the lesson
group_name (Optional[str]): Name of the group.
group_names (Optional[List[str]]): Name of the groups.
exempted (bool): Specifies if the student's presence is exempt.
Expand Down
6 changes: 6 additions & 0 deletions pronotepy/test_pronotepy.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ def test_absences(self) -> None:
all_absences.extend(period.absences)
self.assertGreater(len(all_absences), 0)

def test_delays(self) -> None:
all_delays = []
for period in client.periods:
all_delays.extend(period.delays)
self.assertGreater(len(all_delays), 0)

def test_punishments(self) -> None:
all_punishments = []
for period in client.periods:
Expand Down