librus-python-api 1.9.0__py3-none-any.whl → 1.10.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- librus_python_api/__init__.py +11 -1
- librus_python_api/config.py +45 -0
- librus_python_api/diagnostics.py +1 -0
- librus_python_api/gateway_grades.py +33 -74
- librus_python_api/grade_records.py +78 -16
- librus_python_api/inspect_page.py +10 -0
- librus_python_api/justifications.py +238 -0
- librus_python_api/models.py +89 -0
- librus_python_api/parsers.py +7 -0
- librus_python_api/service.py +46 -3
- {librus_python_api-1.9.0.dist-info → librus_python_api-1.10.0.dist-info}/METADATA +8 -4
- {librus_python_api-1.9.0.dist-info → librus_python_api-1.10.0.dist-info}/RECORD +14 -13
- {librus_python_api-1.9.0.dist-info → librus_python_api-1.10.0.dist-info}/WHEEL +0 -0
- {librus_python_api-1.9.0.dist-info → librus_python_api-1.10.0.dist-info}/licenses/LICENSE +0 -0
librus_python_api/__init__.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""Independent bounded async client. General live compatibility is unqualified."""
|
|
2
2
|
|
|
3
3
|
# Before the imports: config reads it for the User-Agent.
|
|
4
|
-
__version__ = "1.
|
|
4
|
+
__version__ = "1.10.0"
|
|
5
5
|
|
|
6
6
|
from librus_python_api.attachments import AttachmentStream, ModernAttachmentStream
|
|
7
7
|
from librus_python_api.budget import RequestBudget
|
|
@@ -38,6 +38,8 @@ from librus_python_api.models import (
|
|
|
38
38
|
AttendanceView,
|
|
39
39
|
AttendanceWindow,
|
|
40
40
|
Availability,
|
|
41
|
+
BehaviourPointEntry,
|
|
42
|
+
BehaviourPoints,
|
|
41
43
|
ClassFreeDay,
|
|
42
44
|
ClassFreeDays,
|
|
43
45
|
CompletedLesson,
|
|
@@ -64,6 +66,9 @@ from librus_python_api.models import (
|
|
|
64
66
|
HomeworkItem,
|
|
65
67
|
HomeworkRangeRequest,
|
|
66
68
|
Identity,
|
|
69
|
+
Justification,
|
|
70
|
+
Justifications,
|
|
71
|
+
JustificationStatus,
|
|
67
72
|
LuckyNumber,
|
|
68
73
|
MessageAttachment,
|
|
69
74
|
MessageAttachmentReference,
|
|
@@ -259,6 +264,8 @@ __all__ = [
|
|
|
259
264
|
"DescriptiveGradeSummary",
|
|
260
265
|
"FinalGrades",
|
|
261
266
|
"FormativeGrade",
|
|
267
|
+
"BehaviourPointEntry",
|
|
268
|
+
"BehaviourPoints",
|
|
262
269
|
"GradeCorrection",
|
|
263
270
|
"GradeKind",
|
|
264
271
|
"GradeRecords",
|
|
@@ -267,6 +274,9 @@ __all__ = [
|
|
|
267
274
|
"GradeView",
|
|
268
275
|
"GradeWindow",
|
|
269
276
|
"Identity",
|
|
277
|
+
"Justification",
|
|
278
|
+
"Justifications",
|
|
279
|
+
"JustificationStatus",
|
|
270
280
|
"LibrusService",
|
|
271
281
|
"LuckyNumber",
|
|
272
282
|
"NumericGrade",
|
librus_python_api/config.py
CHANGED
|
@@ -503,6 +503,17 @@ ENDPOINTS: Mapping[str, Endpoint] = MappingProxyType(
|
|
|
503
503
|
True,
|
|
504
504
|
Evidence.INDEPENDENTLY_OBSERVED,
|
|
505
505
|
),
|
|
506
|
+
# The e-Justifications list as the page shows it unfiltered. Both
|
|
507
|
+
# parent logins got it, both student logins the "Brak dostępu"
|
|
508
|
+
# page (2026-11-13). The filter form's POST is not used.
|
|
509
|
+
Endpoint(
|
|
510
|
+
"justifications",
|
|
511
|
+
"GET",
|
|
512
|
+
"/eusprawiedliwienia",
|
|
513
|
+
SideEffect.NONE,
|
|
514
|
+
True,
|
|
515
|
+
Evidence.INDEPENDENTLY_OBSERVED,
|
|
516
|
+
),
|
|
506
517
|
Endpoint(
|
|
507
518
|
"gateway_attendance",
|
|
508
519
|
"GET",
|
|
@@ -877,6 +888,11 @@ FORMATIVE_DETAIL_PATH_PREFIX = "/przegladaj_oceny/szczegoly/ksztaltujace/"
|
|
|
877
888
|
BEHAVIOUR_POINTS_DETAIL_PATH_PREFIX = "/przegladaj_oceny/zachowanie_szczegoly/"
|
|
878
889
|
# Tooltip labels of a behaviour grade symbol entry (#114, synthetic example).
|
|
879
890
|
BEHAVIOUR_GRADE_LABELS = frozenset({"Data wystawienia", "Dodał", "Komentarz"})
|
|
891
|
+
# Tooltip labels after a behaviour-point entry's unlabelled first line, as the
|
|
892
|
+
# 1.6.2 synthetic entry has them; any other label fails the read (#138).
|
|
893
|
+
BEHAVIOUR_POINT_LABELS = frozenset(
|
|
894
|
+
{"Zakres od", "Zakres do", "Data wystawienia", "Dodał", "Komentarz"}
|
|
895
|
+
)
|
|
880
896
|
# Recognition only: point-grade detail links are classified, never requested.
|
|
881
897
|
POINT_GRADE_DETAIL_PATH_PREFIX = "/przegladaj_oceny_punktowe/szczegoly/"
|
|
882
898
|
# Recognition only: an ordinary grade's own detail link gives its stable grade
|
|
@@ -1034,6 +1050,35 @@ PAGE_NOTICES = MappingProxyType(
|
|
|
1034
1050
|
)
|
|
1035
1051
|
MODULE_UNAVAILABLE_PATH = "/modul_niedostepny"
|
|
1036
1052
|
CLASS_FREE_DAYS_MAX_RECORDS = 4096
|
|
1053
|
+
# e-Justifications list (`/eusprawiedliwienia`, structure observed on two
|
|
1054
|
+
# parent logins on 2026-11-13). The list table's classes, its seven header
|
|
1055
|
+
# cells in page order (`td`, not `th`, in `thead`) and the status words. The
|
|
1056
|
+
# status words are the filter's options; `odrzucone` has not been seen on an
|
|
1057
|
+
# entry. A decided entry adds " (" + the deciding person's name + ")".
|
|
1058
|
+
JUSTIFICATION_TABLE_CLASSES = frozenset({"decorated", "stretch", "center"})
|
|
1059
|
+
JUSTIFICATION_HEADERS = (
|
|
1060
|
+
"Załącznik",
|
|
1061
|
+
"Okres usprawiedliwienia",
|
|
1062
|
+
"Liczba usprawiedliwionych nieobecności",
|
|
1063
|
+
"Treść",
|
|
1064
|
+
"Powiadomieni nauczyciele",
|
|
1065
|
+
"Data wysłania",
|
|
1066
|
+
"Status",
|
|
1067
|
+
)
|
|
1068
|
+
JUSTIFICATION_STATUSES = MappingProxyType(
|
|
1069
|
+
{"wysłane": "sent", "usprawiedliwione": "justified", "odrzucone": "rejected"}
|
|
1070
|
+
)
|
|
1071
|
+
# `Me.Account.GroupId` of the logins that may request the list: 5 on both
|
|
1072
|
+
# parent logins, 8 on both student logins (one school, 2026-11-13). Opening
|
|
1073
|
+
# the list on a student login ends its session, so any other or missing group
|
|
1074
|
+
# is refused before the request.
|
|
1075
|
+
JUSTIFICATION_ACCOUNT_GROUP = 5
|
|
1076
|
+
# The filter form's date inputs, filled with the window the list shows.
|
|
1077
|
+
JUSTIFICATION_WINDOW_FIELDS = ("data_od", "data_do")
|
|
1078
|
+
JUSTIFICATION_MAX_ITEMS = 512
|
|
1079
|
+
JUSTIFICATION_MAX_CONTENT_LENGTH = 8192
|
|
1080
|
+
JUSTIFICATION_MAX_TEACHERS = 64
|
|
1081
|
+
JUSTIFICATION_MAX_TOTAL_TEXT_LENGTH = 262144
|
|
1037
1082
|
COMPLETED_LESSONS_MAX_WINDOW_DAYS = 371
|
|
1038
1083
|
COMPLETED_LESSONS_MAX_PAGE_COUNT = 1000
|
|
1039
1084
|
COMPLETED_LESSONS_MAX_PAGE_ITEMS = 256
|
librus_python_api/diagnostics.py
CHANGED
|
@@ -255,6 +255,7 @@ def _redaction_vocabulary() -> tuple[
|
|
|
255
255
|
*config.GRADE_PERIOD_HEADERS,
|
|
256
256
|
*config.GRADE_PREDICTED_PERIOD_HEADERS,
|
|
257
257
|
*config.GRADE_AVERAGE_HEADERS,
|
|
258
|
+
*config.JUSTIFICATION_HEADERS,
|
|
258
259
|
}
|
|
259
260
|
texts |= {label.casefold() for label in config.FORMATIVE_HEADERS}
|
|
260
261
|
profile = (*config.PROFILE_LABELS, *config.PROFILE_OWNER_LABELS)
|
|
@@ -4,8 +4,10 @@ The grades page of a school on the new descriptive grading schema renders a
|
|
|
4
4
|
subject table whose semester cells are empty; the page script then loads the
|
|
5
5
|
grades from gateway JSON routes. Routes and field names come from public client
|
|
6
6
|
code and the official page script. One authorized read on 2026-10-28 parsed four
|
|
7
|
-
PartialGrades records on one school
|
|
8
|
-
|
|
7
|
+
PartialGrades records on one school. A structure-only read on 2026-11-13 recorded
|
|
8
|
+
the pagination member, `{"limit", "page", "total"}` integers beside `data` or
|
|
9
|
+
`Users` (Subjects has none), and only that member is checked; every unexpected
|
|
10
|
+
shape fails instead of producing a partial collection.
|
|
9
11
|
|
|
10
12
|
Another school renders the same table with plain text in its semester cells and
|
|
11
13
|
no script hooks (#115, from a reporter's synthetic example). The grade record
|
|
@@ -55,29 +57,6 @@ _DATE = re.compile(
|
|
|
55
57
|
r"(?:[T ][0-9]{2}:[0-9]{2}(?::[0-9]{2}(?:\.[0-9]{1,9})?)?"
|
|
56
58
|
r"(?:Z|[+-][0-9]{2}:?[0-9]{2})?)?"
|
|
57
59
|
)
|
|
58
|
-
# Keys (lower case, without separators) that, in any object beside `data`,
|
|
59
|
-
# show that the collection continues on another page.
|
|
60
|
-
_TOTAL_KEYS = frozenset(
|
|
61
|
-
{
|
|
62
|
-
"total",
|
|
63
|
-
"totalcount",
|
|
64
|
-
"totalitems",
|
|
65
|
-
"totalrecords",
|
|
66
|
-
"totalresults",
|
|
67
|
-
"count",
|
|
68
|
-
"itemcount",
|
|
69
|
-
"itemscount",
|
|
70
|
-
"recordcount",
|
|
71
|
-
}
|
|
72
|
-
)
|
|
73
|
-
_PAGE_COUNT_KEYS = frozenset(
|
|
74
|
-
{"pages", "totalpages", "pagecount", "pagescount", "lastpage", "numberofpages"}
|
|
75
|
-
)
|
|
76
|
-
_NEXT_KEYS = frozenset({"next", "nextpage", "nexturl", "nextpageurl", "nextlink"})
|
|
77
|
-
_MORE_KEYS = frozenset({"hasmore", "hasnext", "hasnextpage", "more"})
|
|
78
|
-
_PAGE_SIZE_KEYS = frozenset(
|
|
79
|
-
{"limit", "perpage", "pagesize", "itemsperpage", "pagelimit"}
|
|
80
|
-
)
|
|
81
60
|
|
|
82
61
|
|
|
83
62
|
class _TokenInfoWire(BaseModel):
|
|
@@ -199,52 +178,33 @@ def _decode_collection(body: bytes, key: str, maximum: int) -> dict[str, Any]:
|
|
|
199
178
|
return data
|
|
200
179
|
|
|
201
180
|
|
|
202
|
-
def
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
return int(value)
|
|
207
|
-
return None
|
|
181
|
+
def _check_pagination(
|
|
182
|
+
envelope: dict[str, Any], received: int, *, required: bool
|
|
183
|
+
) -> None:
|
|
184
|
+
"""Read the recorded `pagination` member; anything else decides nothing.
|
|
208
185
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
total above the items received, more than one page, a next link or page,
|
|
216
|
-
a true has-more flag, or a full page of a stated size with no total.
|
|
186
|
+
Observed 2026-11-13: `{"limit": int, "page": int, "total": int}` beside
|
|
187
|
+
`data` (PartialGrades) or `Users`. Subjects carries no member. Only the
|
|
188
|
+
first page is ever read, so the member must show page 1 and a total equal
|
|
189
|
+
to the items received (the limit is not a fixed page size and is only
|
|
190
|
+
checked to be an integer). Anything else fails instead of returning a
|
|
191
|
+
possibly partial collection.
|
|
217
192
|
"""
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
pending.append((value, depth + 1))
|
|
234
|
-
continue
|
|
235
|
-
number = _count(value)
|
|
236
|
-
if name in _TOTAL_KEYS and number is not None:
|
|
237
|
-
totals.append(number)
|
|
238
|
-
elif name in _PAGE_COUNT_KEYS and number is not None:
|
|
239
|
-
more = more or number > 1
|
|
240
|
-
elif name in _MORE_KEYS:
|
|
241
|
-
more = more or value is True
|
|
242
|
-
elif name in _PAGE_SIZE_KEYS and number is not None:
|
|
243
|
-
sizes.append(number)
|
|
244
|
-
if any(total > received for total in totals):
|
|
245
|
-
return True
|
|
246
|
-
full_page = any(0 < size <= received for size in sizes)
|
|
247
|
-
return more or (full_page and not totals)
|
|
193
|
+
if "pagination" not in envelope:
|
|
194
|
+
if required:
|
|
195
|
+
raise LibrusError(ErrorKind.PARSE)
|
|
196
|
+
return
|
|
197
|
+
member = envelope["pagination"]
|
|
198
|
+
if not isinstance(member, dict):
|
|
199
|
+
raise LibrusError(ErrorKind.PARSE)
|
|
200
|
+
limit, page, total = member.get("limit"), member.get("page"), member.get("total")
|
|
201
|
+
# `type(...) is int` rejects booleans, strings and floats.
|
|
202
|
+
if type(limit) is not int or type(page) is not int or type(total) is not int:
|
|
203
|
+
raise LibrusError(ErrorKind.PARSE)
|
|
204
|
+
if limit < 1 or total < received:
|
|
205
|
+
raise LibrusError(ErrorKind.PARSE)
|
|
206
|
+
if page != 1 or total > received:
|
|
207
|
+
raise LibrusError(ErrorKind.UNSUPPORTED_CAPABILITY)
|
|
248
208
|
|
|
249
209
|
|
|
250
210
|
def parse_token_info(body: bytes) -> str:
|
|
@@ -281,9 +241,8 @@ def _day(value: str) -> date:
|
|
|
281
241
|
def parse_partial_grades(body: bytes) -> tuple[PartialGrade, ...]:
|
|
282
242
|
data = _decode_collection(body, "data", GRADE_MAX_RECORDS)
|
|
283
243
|
wire = _validate(_PartialGradesWire, data)
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
raise LibrusError(ErrorKind.UNSUPPORTED_CAPABILITY)
|
|
244
|
+
# Returning the first page alone would be a silently partial result.
|
|
245
|
+
_check_pagination(data, len(wire.data), required=True)
|
|
287
246
|
return tuple(
|
|
288
247
|
PartialGrade(
|
|
289
248
|
item.subjectId,
|
|
@@ -303,8 +262,7 @@ def parse_partial_grades(body: bytes) -> tuple[PartialGrade, ...]:
|
|
|
303
262
|
def parse_gateway_subjects(body: bytes) -> Mapping[str, GatewaySubject]:
|
|
304
263
|
data = _decode_collection(body, "data", DESCRIPTIVE_MAX_SUBJECTS)
|
|
305
264
|
wire = _validate(_SubjectsWire, data)
|
|
306
|
-
|
|
307
|
-
raise LibrusError(ErrorKind.UNSUPPORTED_CAPABILITY)
|
|
265
|
+
_check_pagination(data, len(wire.data), required=False)
|
|
308
266
|
result: dict[str, GatewaySubject] = {}
|
|
309
267
|
numeric: set[int] = set()
|
|
310
268
|
for item in wire.data:
|
|
@@ -323,6 +281,7 @@ def parse_gateway_users(body: bytes) -> Mapping[str, str]:
|
|
|
323
281
|
"""Account IDs to "LastName FirstName"; a user with neither is omitted."""
|
|
324
282
|
data = _decode_collection(body, "Users", DESCRIPTIVE_MAX_USERS)
|
|
325
283
|
wire = _validate(_UsersWire, data)
|
|
284
|
+
_check_pagination(data, len(wire.Users), required=False)
|
|
326
285
|
result: dict[str, str] = {}
|
|
327
286
|
seen: dict[str, tuple[str | None, str | None]] = {}
|
|
328
287
|
for user in wire.Users:
|
|
@@ -9,6 +9,7 @@ from lxml import html
|
|
|
9
9
|
from librus_python_api import markup
|
|
10
10
|
from librus_python_api.config import (
|
|
11
11
|
BEHAVIOUR_GRADE_LABELS,
|
|
12
|
+
BEHAVIOUR_POINT_LABELS,
|
|
12
13
|
BEHAVIOUR_POINTS_DETAIL_PATH_PREFIX,
|
|
13
14
|
FORMATIVE_DETAIL_PATH_PREFIX,
|
|
14
15
|
GRADE_AVERAGE_HEADERS,
|
|
@@ -45,6 +46,8 @@ from librus_python_api.grade_parsers import (
|
|
|
45
46
|
)
|
|
46
47
|
from librus_python_api.models import (
|
|
47
48
|
Availability,
|
|
49
|
+
BehaviourPointEntry,
|
|
50
|
+
BehaviourPoints,
|
|
48
51
|
DescriptiveGrade,
|
|
49
52
|
DescriptiveGradeSummary,
|
|
50
53
|
FormativeGrade,
|
|
@@ -224,14 +227,17 @@ class _Collection:
|
|
|
224
227
|
point_subjects: set[str] = field(default_factory=set, repr=False)
|
|
225
228
|
consumed: set[html.HtmlElement] = field(default_factory=set, repr=False)
|
|
226
229
|
publication_rows: set[html.HtmlElement] = field(default_factory=set, repr=False)
|
|
230
|
+
behaviour: list[BehaviourPoints] = field(default_factory=list, repr=False)
|
|
227
231
|
formative: int = 0
|
|
228
232
|
|
|
229
|
-
def check_size(self) -> None:
|
|
233
|
+
def check_size(self, pending: int = 0) -> None:
|
|
230
234
|
if (
|
|
231
235
|
len(self.numeric)
|
|
232
236
|
+ len(self.descriptive)
|
|
233
237
|
+ len(self.descriptive_summaries)
|
|
234
238
|
+ self.formative
|
|
239
|
+
+ sum(len(item.entries) for item in self.behaviour)
|
|
240
|
+
+ pending
|
|
235
241
|
> GRADE_MAX_RECORDS
|
|
236
242
|
):
|
|
237
243
|
raise LibrusError(ErrorKind.LIMIT)
|
|
@@ -343,13 +349,51 @@ def _read_corrections(
|
|
|
343
349
|
collection.corrections.append(correction)
|
|
344
350
|
|
|
345
351
|
|
|
346
|
-
def
|
|
347
|
-
"""
|
|
352
|
+
def _behaviour_point_entry(element: html.HtmlElement) -> BehaviourPointEntry:
|
|
353
|
+
"""A point entry's link: signed points, detail ID and its tooltip.
|
|
348
354
|
|
|
349
|
-
The
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
355
|
+
The tooltip has an unlabelled first line, the category, then only
|
|
356
|
+
`config.BEHAVIOUR_POINT_LABELS`; `Data wystawienia` is required. A first
|
|
357
|
+
line that is a known label means the category is missing and fails.
|
|
358
|
+
"""
|
|
359
|
+
detail = markup.detail_id(element.get("href"), BEHAVIOUR_POINTS_DETAIL_PATH_PREFIX)
|
|
360
|
+
raw = markup.text(element)
|
|
361
|
+
if detail is None or not re.fullmatch(r"[+-]?[0-9]{1,4}", raw):
|
|
362
|
+
raise LibrusError(ErrorKind.PARSE)
|
|
363
|
+
heading: list[str] = []
|
|
364
|
+
metadata = markup.tooltip_fields(element, heading)
|
|
365
|
+
if (
|
|
366
|
+
not heading
|
|
367
|
+
or heading[0].partition(":")[0].strip() in TOOLTIP_LABELS
|
|
368
|
+
or not BEHAVIOUR_POINT_LABELS >= metadata.keys()
|
|
369
|
+
):
|
|
370
|
+
raise LibrusError(ErrorKind.PARSE)
|
|
371
|
+
return BehaviourPointEntry(
|
|
372
|
+
int(raw),
|
|
373
|
+
detail,
|
|
374
|
+
heading[0],
|
|
375
|
+
markup.civil_date(metadata.get("Data wystawienia")),
|
|
376
|
+
tuple(metadata.items()),
|
|
377
|
+
)
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def _behaviour_points(
|
|
381
|
+
cell: html.HtmlElement,
|
|
382
|
+
period: Literal[1, 2] | None,
|
|
383
|
+
collection: _Collection,
|
|
384
|
+
*,
|
|
385
|
+
points: bool = False,
|
|
386
|
+
) -> bool:
|
|
387
|
+
"""Read a behaviour-points cell into `collection.behaviour`; not grades.
|
|
388
|
+
|
|
389
|
+
The cell holds one tooltip span showing an integer, the tally (its title
|
|
390
|
+
is not interpreted), and point entries linking to behaviour details, each
|
|
391
|
+
with its own tooltip. Any other content next to the tally fails instead of
|
|
392
|
+
being skipped. The point table may show the same cell again: an equal item
|
|
393
|
+
is one item, a different one for the same period fails, and only an item
|
|
394
|
+
that is appended counts toward `GRADE_MAX_RECORDS`. A cell spanning both
|
|
395
|
+
periods (`period` None) holds no entries and is validated, not recorded:
|
|
396
|
+
its period would be a guess.
|
|
353
397
|
"""
|
|
354
398
|
tallies = [
|
|
355
399
|
node
|
|
@@ -360,15 +404,20 @@ def _behaviour_points(cell: html.HtmlElement, collection: _Collection) -> bool:
|
|
|
360
404
|
return False
|
|
361
405
|
elements = [node for node in cell if isinstance(node.tag, str)]
|
|
362
406
|
boxes = [node for node in elements if node not in tallies]
|
|
407
|
+
tally = markup.text(tallies[0])
|
|
363
408
|
if (
|
|
364
409
|
len(tallies) != 1
|
|
365
410
|
or len(tallies[0])
|
|
366
|
-
or not re.fullmatch(r"-?[0-9]{1,4}",
|
|
411
|
+
or not re.fullmatch(r"-?[0-9]{1,4}", tally)
|
|
367
412
|
or (cell.text or "").strip()
|
|
368
413
|
or any((node.tail or "").strip() for node in cell)
|
|
369
414
|
or _boxes(cell) != boxes
|
|
370
415
|
):
|
|
371
416
|
raise LibrusError(ErrorKind.PARSE)
|
|
417
|
+
same = [known for known in collection.behaviour if known.semester == period]
|
|
418
|
+
if same and not points:
|
|
419
|
+
raise LibrusError(ErrorKind.PARSE)
|
|
420
|
+
entries = []
|
|
372
421
|
for box in boxes:
|
|
373
422
|
anchors = [node for node in box if isinstance(node.tag, str)]
|
|
374
423
|
if (
|
|
@@ -376,14 +425,20 @@ def _behaviour_points(cell: html.HtmlElement, collection: _Collection) -> bool:
|
|
|
376
425
|
or len(anchors) != 1
|
|
377
426
|
or anchors[0].tag != "a"
|
|
378
427
|
or len(anchors[0])
|
|
379
|
-
or markup.detail_id(
|
|
380
|
-
anchors[0].get("href"), BEHAVIOUR_POINTS_DETAIL_PATH_PREFIX
|
|
381
|
-
)
|
|
382
|
-
is None
|
|
383
|
-
or not re.fullmatch(r"[+-]?[0-9]{1,4}", markup.text(anchors[0]))
|
|
384
428
|
):
|
|
385
429
|
raise LibrusError(ErrorKind.PARSE)
|
|
386
|
-
|
|
430
|
+
entries.append(_behaviour_point_entry(anchors[0]))
|
|
431
|
+
if not same:
|
|
432
|
+
collection.check_size(len(entries))
|
|
433
|
+
elif len(entries) > len(same[0].entries):
|
|
434
|
+
raise LibrusError(ErrorKind.PARSE)
|
|
435
|
+
if period is not None:
|
|
436
|
+
item = BehaviourPoints(period, int(tally), tuple(entries))
|
|
437
|
+
if not same:
|
|
438
|
+
collection.behaviour.append(item)
|
|
439
|
+
elif same != [item]:
|
|
440
|
+
raise LibrusError(ErrorKind.PARSE)
|
|
441
|
+
collection.consumed.update(boxes)
|
|
387
442
|
return True
|
|
388
443
|
|
|
389
444
|
|
|
@@ -563,14 +618,20 @@ def _read_numeric_table(
|
|
|
563
618
|
)
|
|
564
619
|
)
|
|
565
620
|
averages.append(SchoolAverage(subject, period, value))
|
|
566
|
-
|
|
621
|
+
spanning = columns[current[0]] is columns[current[1]]
|
|
622
|
+
if spanning and _boxes(columns[current[0]]):
|
|
567
623
|
raise LibrusError(ErrorKind.PARSE)
|
|
568
624
|
seen: set[html.HtmlElement] = set()
|
|
569
625
|
for period, index in enumerate(current, start=1):
|
|
570
626
|
if columns[index] not in seen:
|
|
571
627
|
if not (
|
|
572
628
|
subject in GRADE_MERGED_SUBJECTS
|
|
573
|
-
and _behaviour_points(
|
|
629
|
+
and _behaviour_points(
|
|
630
|
+
columns[index],
|
|
631
|
+
None if spanning else cast(Literal[1, 2], period),
|
|
632
|
+
collection,
|
|
633
|
+
points=points,
|
|
634
|
+
)
|
|
574
635
|
):
|
|
575
636
|
start = len(collection.numeric)
|
|
576
637
|
_entries(
|
|
@@ -768,4 +829,5 @@ def read_grade_records(document: html.HtmlElement) -> GradeRecords:
|
|
|
768
829
|
formative,
|
|
769
830
|
tuple(collection.point_results),
|
|
770
831
|
tuple(collection.corrections),
|
|
832
|
+
tuple(collection.behaviour),
|
|
771
833
|
)
|
|
@@ -21,6 +21,7 @@ from librus_python_api.diagnostics import describe_failure, failure_frames
|
|
|
21
21
|
from librus_python_api.exceptions import LibrusError
|
|
22
22
|
from librus_python_api.gateway_grades import parse_grade_page
|
|
23
23
|
from librus_python_api.grade_parsers import parse_final_grades
|
|
24
|
+
from librus_python_api.justifications import parse_justifications
|
|
24
25
|
from librus_python_api.models import Availability
|
|
25
26
|
from librus_python_api.parsers import parse_profile
|
|
26
27
|
|
|
@@ -43,6 +44,10 @@ def _grades(body: bytes) -> dict[str, int]:
|
|
|
43
44
|
"point_results": len(records.point_results),
|
|
44
45
|
"formative": len(records.formative),
|
|
45
46
|
"corrections": len(records.corrections),
|
|
47
|
+
"behaviour_points": len(records.behaviour_points),
|
|
48
|
+
"behaviour_point_entries": sum(
|
|
49
|
+
len(item.entries) for item in records.behaviour_points
|
|
50
|
+
),
|
|
46
51
|
"descriptive_table": int(table is not None),
|
|
47
52
|
"descriptive_table_filled": int(table is not None and table.filled),
|
|
48
53
|
}
|
|
@@ -57,10 +62,15 @@ def _profile(body: bytes) -> dict[str, int]:
|
|
|
57
62
|
return {"lucky_number": int(lucky == Availability.AVAILABLE)}
|
|
58
63
|
|
|
59
64
|
|
|
65
|
+
def _justifications(body: bytes) -> dict[str, int]:
|
|
66
|
+
return {"entries": len(parse_justifications(body)[2])}
|
|
67
|
+
|
|
68
|
+
|
|
60
69
|
PARSERS: dict[str, Callable[[bytes], dict[str, int]]] = {
|
|
61
70
|
"grades": _grades,
|
|
62
71
|
"final-grades": _final_grades,
|
|
63
72
|
"profile": _profile,
|
|
73
|
+
"justifications": _justifications,
|
|
64
74
|
}
|
|
65
75
|
# macOS TextEdit saves a viewed page source as a new document holding the
|
|
66
76
|
# source as text, not the page itself.
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"""Bounded e-Justifications list, independently authored from observed structure.
|
|
2
|
+
|
|
3
|
+
Fixtures and this parser follow a structure-only observation of two parent
|
|
4
|
+
logins (2026-11-13); no captured text is used.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import re
|
|
8
|
+
from datetime import date, datetime
|
|
9
|
+
|
|
10
|
+
from lxml import html
|
|
11
|
+
|
|
12
|
+
from librus_python_api import markup
|
|
13
|
+
from librus_python_api.config import (
|
|
14
|
+
JUSTIFICATION_HEADERS,
|
|
15
|
+
JUSTIFICATION_MAX_CONTENT_LENGTH,
|
|
16
|
+
JUSTIFICATION_MAX_ITEMS,
|
|
17
|
+
JUSTIFICATION_MAX_TEACHERS,
|
|
18
|
+
JUSTIFICATION_MAX_TOTAL_TEXT_LENGTH,
|
|
19
|
+
JUSTIFICATION_STATUSES,
|
|
20
|
+
JUSTIFICATION_TABLE_CLASSES,
|
|
21
|
+
JUSTIFICATION_WINDOW_FIELDS,
|
|
22
|
+
)
|
|
23
|
+
from librus_python_api.exceptions import ErrorKind, LibrusError
|
|
24
|
+
from librus_python_api.models import Justification, JustificationStatus
|
|
25
|
+
from librus_python_api.parsers import parse_page
|
|
26
|
+
|
|
27
|
+
_DAY = r"([0-9]{4}-[0-9]{2}-[0-9]{2})"
|
|
28
|
+
_RANGE = re.compile(rf"od {_DAY} do {_DAY}")
|
|
29
|
+
# "lekcja" (one lesson) and "lekcje" were observed; "lekcji" is Polish for
|
|
30
|
+
# five or more and is accepted with them.
|
|
31
|
+
_ONE_DAY = re.compile(rf"{_DAY}, lekcj[aei]: ([0-9]{{1,2}}(?:, [0-9]{{1,2}})*)")
|
|
32
|
+
_SENT = re.compile(rf"{_DAY} ([0-9]{{2}}:[0-9]{{2}}:[0-9]{{2}})")
|
|
33
|
+
_STATUS = re.compile(r"(\S+)(?: \((.+)\))?")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _fail(kind: ErrorKind = ErrorKind.PARSE) -> LibrusError:
|
|
37
|
+
return LibrusError(kind)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _day(value: str) -> date:
|
|
41
|
+
try:
|
|
42
|
+
return date.fromisoformat(value)
|
|
43
|
+
except ValueError:
|
|
44
|
+
raise _fail() from None
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _table(document: html.HtmlElement) -> html.HtmlElement:
|
|
48
|
+
tables = [
|
|
49
|
+
table
|
|
50
|
+
for table in document.iter("table")
|
|
51
|
+
if JUSTIFICATION_TABLE_CLASSES <= set(table.get("class", "").split())
|
|
52
|
+
]
|
|
53
|
+
if len(tables) != 1:
|
|
54
|
+
raise _fail()
|
|
55
|
+
table = tables[0]
|
|
56
|
+
if next(table.iterancestors("table"), None) is not None:
|
|
57
|
+
raise _fail()
|
|
58
|
+
return table
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _section(row: html.HtmlElement) -> str:
|
|
62
|
+
parent = row.getparent()
|
|
63
|
+
return str(parent.tag) if parent is not None else ""
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _header(rows: list[html.HtmlElement]) -> None:
|
|
67
|
+
if len(rows) != 1:
|
|
68
|
+
raise _fail()
|
|
69
|
+
cells = markup.cells(rows[0])
|
|
70
|
+
labels = tuple(markup.text(cell) for cell in cells)
|
|
71
|
+
if labels != JUSTIFICATION_HEADERS:
|
|
72
|
+
raise _fail()
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _window(document: html.HtmlElement) -> tuple[date, date]:
|
|
76
|
+
days: list[date] = []
|
|
77
|
+
for name in JUSTIFICATION_WINDOW_FIELDS:
|
|
78
|
+
inputs = [node for node in document.iter("input") if node.get("name") == name]
|
|
79
|
+
if len(inputs) != 1:
|
|
80
|
+
raise _fail()
|
|
81
|
+
value = inputs[0].get("value", "").strip()
|
|
82
|
+
if not re.fullmatch(_DAY, value):
|
|
83
|
+
raise _fail()
|
|
84
|
+
days.append(_day(value))
|
|
85
|
+
if days[0] > days[1]:
|
|
86
|
+
raise _fail()
|
|
87
|
+
for select in document.iter("select"):
|
|
88
|
+
if select.get("name") != "status":
|
|
89
|
+
continue
|
|
90
|
+
chosen = [
|
|
91
|
+
o.get("value") for o in select.iter("option") if "selected" in o.attrib
|
|
92
|
+
]
|
|
93
|
+
# A list narrowed to one status would be a silently partial result.
|
|
94
|
+
if any(value not in (None, "", "0") for value in chosen):
|
|
95
|
+
raise _fail(ErrorKind.UNSUPPORTED_CAPABILITY)
|
|
96
|
+
return days[0], days[1]
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _period(text: str) -> tuple[date, date, tuple[int, ...]]:
|
|
100
|
+
match = _RANGE.fullmatch(text)
|
|
101
|
+
if match:
|
|
102
|
+
start, end = _day(match[1]), _day(match[2])
|
|
103
|
+
if start > end:
|
|
104
|
+
raise _fail()
|
|
105
|
+
return start, end, ()
|
|
106
|
+
match = _ONE_DAY.fullmatch(text)
|
|
107
|
+
if not match:
|
|
108
|
+
raise _fail()
|
|
109
|
+
day = _day(match[1])
|
|
110
|
+
lessons = tuple(int(item) for item in match[2].split(", "))
|
|
111
|
+
if len(set(lessons)) != len(lessons):
|
|
112
|
+
raise _fail()
|
|
113
|
+
return day, day, lessons
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _teachers(cell: html.HtmlElement) -> tuple[str, ...]:
|
|
117
|
+
text = markup.text(cell, markup.FIELD_LENGTH * 8, multiline=True)
|
|
118
|
+
names = tuple(
|
|
119
|
+
name
|
|
120
|
+
for line in text.splitlines()
|
|
121
|
+
for part in line.split(",")
|
|
122
|
+
if (name := part.strip())
|
|
123
|
+
)
|
|
124
|
+
if len(names) > JUSTIFICATION_MAX_TEACHERS:
|
|
125
|
+
raise _fail(ErrorKind.LIMIT)
|
|
126
|
+
if any(len(name) > markup.FIELD_LENGTH for name in names):
|
|
127
|
+
raise _fail(ErrorKind.LIMIT)
|
|
128
|
+
return names
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _status(text: str) -> tuple[JustificationStatus, str | None]:
|
|
132
|
+
match = _STATUS.fullmatch(text)
|
|
133
|
+
if not match:
|
|
134
|
+
raise _fail()
|
|
135
|
+
value = JUSTIFICATION_STATUSES.get(match[1].casefold())
|
|
136
|
+
if value is None:
|
|
137
|
+
raise _fail()
|
|
138
|
+
decided_by = match[2].strip() if match[2] is not None else None
|
|
139
|
+
if decided_by == "":
|
|
140
|
+
raise _fail()
|
|
141
|
+
return JustificationStatus(value), decided_by
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _has_content(cell: html.HtmlElement) -> bool:
|
|
145
|
+
# The attachment cell was empty on every observed entry; its filled markup
|
|
146
|
+
# is unknown, so only its presence is reported and nothing is followed.
|
|
147
|
+
return len(cell) > 0 or bool((cell.text or "").strip())
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _entry(row: html.HtmlElement) -> Justification:
|
|
151
|
+
cells = markup.cells(row)
|
|
152
|
+
if len(cells) != len(JUSTIFICATION_HEADERS):
|
|
153
|
+
raise _fail()
|
|
154
|
+
if any(
|
|
155
|
+
cell.get("colspan", "1") != "1" or cell.get("rowspan", "1") != "1"
|
|
156
|
+
for cell in cells
|
|
157
|
+
):
|
|
158
|
+
raise _fail()
|
|
159
|
+
attachment, period, count, content, teachers, sent, status = cells
|
|
160
|
+
start, end, lessons = _period(markup.text(period))
|
|
161
|
+
count_text = markup.text(count)
|
|
162
|
+
if not re.fullmatch(r"[0-9]{1,4}", count_text):
|
|
163
|
+
raise _fail()
|
|
164
|
+
sent_match = _SENT.fullmatch(markup.text(sent))
|
|
165
|
+
if not sent_match:
|
|
166
|
+
raise _fail()
|
|
167
|
+
try:
|
|
168
|
+
sent_at = datetime.fromisoformat(f"{sent_match[1]} {sent_match[2]}")
|
|
169
|
+
except ValueError:
|
|
170
|
+
raise _fail() from None
|
|
171
|
+
state, decided_by = _status(markup.text(status))
|
|
172
|
+
return Justification(
|
|
173
|
+
start=start,
|
|
174
|
+
end=end,
|
|
175
|
+
lessons=lessons,
|
|
176
|
+
absence_count=int(count_text),
|
|
177
|
+
content=markup.text(content, JUSTIFICATION_MAX_CONTENT_LENGTH, multiline=True),
|
|
178
|
+
teachers=_teachers(teachers),
|
|
179
|
+
sent_at=sent_at,
|
|
180
|
+
status=state,
|
|
181
|
+
decided_by=decided_by,
|
|
182
|
+
has_attachment=_has_content(attachment),
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def _is_empty_marker(rows: list[html.HtmlElement]) -> bool:
|
|
187
|
+
"""The explicit empty row: one cell spanning the whole table.
|
|
188
|
+
|
|
189
|
+
Recorded for a login without entries; its exact markup was not captured,
|
|
190
|
+
so only this structural shape is accepted and its text is not read.
|
|
191
|
+
"""
|
|
192
|
+
if len(rows) != 1:
|
|
193
|
+
return False
|
|
194
|
+
cells = markup.cells(rows[0])
|
|
195
|
+
return (
|
|
196
|
+
len(cells) == 1
|
|
197
|
+
and cells[0].get("colspan") == str(len(JUSTIFICATION_HEADERS))
|
|
198
|
+
and bool(markup.text(cells[0]))
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def parse_justifications(
|
|
203
|
+
body: bytes,
|
|
204
|
+
) -> tuple[date, date, tuple[Justification, ...]]:
|
|
205
|
+
"""The list's window and entries.
|
|
206
|
+
|
|
207
|
+
The "Brak dostępu" page fails as PARSE like any page without the list;
|
|
208
|
+
the client treats it as a session Synergia no longer knows.
|
|
209
|
+
"""
|
|
210
|
+
document = parse_page(body)
|
|
211
|
+
table = _table(document)
|
|
212
|
+
window = _window(document)
|
|
213
|
+
header: list[html.HtmlElement] = []
|
|
214
|
+
body_rows: list[html.HtmlElement] = []
|
|
215
|
+
for row in markup.rows(table):
|
|
216
|
+
section = _section(row)
|
|
217
|
+
if section == "thead":
|
|
218
|
+
header.append(row)
|
|
219
|
+
elif section == "tfoot":
|
|
220
|
+
if markup.text(row):
|
|
221
|
+
raise _fail()
|
|
222
|
+
else:
|
|
223
|
+
body_rows.append(row)
|
|
224
|
+
_header(header)
|
|
225
|
+
if _is_empty_marker(body_rows):
|
|
226
|
+
return (*window, ())
|
|
227
|
+
if len(body_rows) > JUSTIFICATION_MAX_ITEMS:
|
|
228
|
+
raise _fail(ErrorKind.LIMIT)
|
|
229
|
+
items: list[Justification] = []
|
|
230
|
+
total = 0
|
|
231
|
+
for row in body_rows:
|
|
232
|
+
item = _entry(row)
|
|
233
|
+
total += len(item.content) + sum(len(name) for name in item.teachers)
|
|
234
|
+
total += len(item.decided_by or "")
|
|
235
|
+
if total > JUSTIFICATION_MAX_TOTAL_TEXT_LENGTH:
|
|
236
|
+
raise _fail(ErrorKind.LIMIT)
|
|
237
|
+
items.append(item)
|
|
238
|
+
return (*window, tuple(items))
|
librus_python_api/models.py
CHANGED
|
@@ -17,6 +17,7 @@ from librus_python_api.exceptions import ErrorKind
|
|
|
17
17
|
type OperationName = Literal[
|
|
18
18
|
"identity",
|
|
19
19
|
"class_free_days",
|
|
20
|
+
"justifications",
|
|
20
21
|
"student_information",
|
|
21
22
|
"final_grades",
|
|
22
23
|
"grades",
|
|
@@ -655,6 +656,46 @@ class ClassFreeDays:
|
|
|
655
656
|
observation: "Observation"
|
|
656
657
|
|
|
657
658
|
|
|
659
|
+
class JustificationStatus(StrEnum):
|
|
660
|
+
SENT = "sent"
|
|
661
|
+
JUSTIFIED = "justified"
|
|
662
|
+
REJECTED = "rejected"
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
@dataclass(frozen=True, slots=True)
|
|
666
|
+
class Justification:
|
|
667
|
+
"""One e-Justifications entry a parent sent.
|
|
668
|
+
|
|
669
|
+
A period of several days has `start < end` and no lessons; a one-day entry
|
|
670
|
+
has `start == end` and the lesson numbers it names, in page order.
|
|
671
|
+
"""
|
|
672
|
+
|
|
673
|
+
start: date = field(repr=False)
|
|
674
|
+
end: date = field(repr=False)
|
|
675
|
+
lessons: tuple[int, ...] = field(repr=False)
|
|
676
|
+
absence_count: int = field(repr=False)
|
|
677
|
+
content: str = field(repr=False)
|
|
678
|
+
teachers: tuple[str, ...] = field(repr=False)
|
|
679
|
+
sent_at: datetime = field(repr=False)
|
|
680
|
+
status: JustificationStatus
|
|
681
|
+
decided_by: str | None = field(repr=False)
|
|
682
|
+
has_attachment: bool
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
@dataclass(frozen=True, slots=True)
|
|
686
|
+
class Justifications:
|
|
687
|
+
"""The list the page shows unfiltered, for `window_start..window_end`.
|
|
688
|
+
|
|
689
|
+
Entries sent before the window may exist and are not included.
|
|
690
|
+
"""
|
|
691
|
+
|
|
692
|
+
identity: "Identity" = field(repr=False)
|
|
693
|
+
window_start: date = field(repr=False)
|
|
694
|
+
window_end: date = field(repr=False)
|
|
695
|
+
items: tuple[Justification, ...] = field(repr=False)
|
|
696
|
+
observation: "Observation"
|
|
697
|
+
|
|
698
|
+
|
|
658
699
|
class GradeKind(StrEnum):
|
|
659
700
|
CURRENT = "current"
|
|
660
701
|
PERIOD = "period"
|
|
@@ -1171,6 +1212,38 @@ class GradeCorrection:
|
|
|
1171
1212
|
grade_ids: tuple[str, ...] = field(repr=False)
|
|
1172
1213
|
|
|
1173
1214
|
|
|
1215
|
+
@dataclass(frozen=True, slots=True)
|
|
1216
|
+
class BehaviourPointEntry:
|
|
1217
|
+
"""One behaviour-point entry of the behaviour row.
|
|
1218
|
+
|
|
1219
|
+
`points` is the entry's signed label and `detail_id` the ID of its
|
|
1220
|
+
behaviour detail link, which is recognised, never requested. `category`
|
|
1221
|
+
is its tooltip's unlabelled first line and `day` its `Data wystawienia`.
|
|
1222
|
+
`metadata` keeps the tooltip's labelled lines in order: `Zakres od`,
|
|
1223
|
+
`Zakres do`, `Data wystawienia`, `Dodał` and `Komentarz`, as present.
|
|
1224
|
+
"""
|
|
1225
|
+
|
|
1226
|
+
points: int = field(repr=False)
|
|
1227
|
+
detail_id: str = field(repr=False)
|
|
1228
|
+
category: str = field(repr=False)
|
|
1229
|
+
day: date = field(repr=False)
|
|
1230
|
+
metadata: tuple[tuple[str, str], ...] = field(repr=False)
|
|
1231
|
+
|
|
1232
|
+
|
|
1233
|
+
@dataclass(frozen=True, slots=True)
|
|
1234
|
+
class BehaviourPoints:
|
|
1235
|
+
"""A behaviour-row cell with points, read from one period's column.
|
|
1236
|
+
|
|
1237
|
+
`tally` is the integer the cell shows. Whether it is the starting points
|
|
1238
|
+
or a running total is not established, so it is not interpreted, and it
|
|
1239
|
+
is not compared with the entries, which are never summed.
|
|
1240
|
+
"""
|
|
1241
|
+
|
|
1242
|
+
semester: Literal[1, 2]
|
|
1243
|
+
tally: int = field(repr=False)
|
|
1244
|
+
entries: tuple[BehaviourPointEntry, ...] = field(repr=False)
|
|
1245
|
+
|
|
1246
|
+
|
|
1174
1247
|
@dataclass(frozen=True, slots=True)
|
|
1175
1248
|
class GradeRecords:
|
|
1176
1249
|
numeric: tuple[NumericGrade, ...] = field(repr=False)
|
|
@@ -1185,6 +1258,8 @@ class GradeRecords:
|
|
|
1185
1258
|
point_results: tuple[SchoolAverage, ...] = field(default=(), repr=False)
|
|
1186
1259
|
# The page's correction brackets; only the all view was seen to show them.
|
|
1187
1260
|
corrections: tuple[GradeCorrection, ...] = field(default=(), repr=False)
|
|
1261
|
+
# The behaviour row's points, apart from grades; empty without points.
|
|
1262
|
+
behaviour_points: tuple[BehaviourPoints, ...] = field(default=(), repr=False)
|
|
1188
1263
|
|
|
1189
1264
|
|
|
1190
1265
|
@dataclass(frozen=True, slots=True)
|
|
@@ -1207,6 +1282,9 @@ class GradeWindow:
|
|
|
1207
1282
|
formative: tuple[FormativeGrade, ...] = field(default=(), repr=False)
|
|
1208
1283
|
# Each correction with at least one of its grades in the window, whole.
|
|
1209
1284
|
corrections: tuple[GradeCorrection, ...] = field(default=(), repr=False)
|
|
1285
|
+
# Each behaviour-points item with an entry in the window, with only those
|
|
1286
|
+
# entries and its tally; a tally without entries stays outside.
|
|
1287
|
+
behaviour_points: tuple[BehaviourPoints, ...] = field(default=(), repr=False)
|
|
1210
1288
|
|
|
1211
1289
|
|
|
1212
1290
|
@dataclass(frozen=True, slots=True)
|
|
@@ -1433,12 +1511,23 @@ class _PersonWire(BaseModel):
|
|
|
1433
1511
|
|
|
1434
1512
|
class _AccountWire(_PersonWire):
|
|
1435
1513
|
UserId: Annotated[str | None, Field(pattern=r"^[A-Za-z0-9_-]{1,64}$")] = None
|
|
1514
|
+
# The login's account group, internal only: 5 on parent and 8 on student
|
|
1515
|
+
# logins observed (2026-11-13). Any value other than a plain integer reads
|
|
1516
|
+
# as unknown, so an unexpected shape never breaks the identity read.
|
|
1517
|
+
GroupId: int | None = None
|
|
1436
1518
|
|
|
1437
1519
|
@field_validator("UserId", mode="before")
|
|
1438
1520
|
@classmethod
|
|
1439
1521
|
def normalize_user_id(cls, value: Any) -> Any:
|
|
1440
1522
|
return cls.normalize_id(value)
|
|
1441
1523
|
|
|
1524
|
+
@field_validator("GroupId", mode="before")
|
|
1525
|
+
@classmethod
|
|
1526
|
+
def normalize_group_id(cls, value: Any) -> Any:
|
|
1527
|
+
if type(value) is int and 0 <= value < 10**9:
|
|
1528
|
+
return value
|
|
1529
|
+
return None
|
|
1530
|
+
|
|
1442
1531
|
|
|
1443
1532
|
class _UserWire(BaseModel):
|
|
1444
1533
|
model_config = ConfigDict(strict=True, extra="ignore", hide_input_in_errors=True)
|
librus_python_api/parsers.py
CHANGED
|
@@ -84,6 +84,12 @@ def _unique_object(pairs: list[tuple[str, Any]]) -> dict[str, Any]:
|
|
|
84
84
|
|
|
85
85
|
|
|
86
86
|
def parse_identity(body: bytes) -> tuple[Person, Person]:
|
|
87
|
+
owner, student, _ = parse_identity_record(body)
|
|
88
|
+
return owner, student
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def parse_identity_record(body: bytes) -> tuple[Person, Person, int | None]:
|
|
92
|
+
"""The login owner, the represented student and the account group, if any."""
|
|
87
93
|
data = decode_json(body)
|
|
88
94
|
failed = False
|
|
89
95
|
envelope: _EnvelopeWire | None = None
|
|
@@ -105,6 +111,7 @@ def parse_identity(body: bytes) -> tuple[Person, Person]:
|
|
|
105
111
|
return (
|
|
106
112
|
Person(account.Id, account.FirstName, account.LastName),
|
|
107
113
|
Person(student_id, user.FirstName, user.LastName),
|
|
114
|
+
account.GroupId,
|
|
108
115
|
)
|
|
109
116
|
|
|
110
117
|
|
librus_python_api/service.py
CHANGED
|
@@ -43,6 +43,7 @@ from librus_python_api.config import (
|
|
|
43
43
|
ENDPOINTS,
|
|
44
44
|
GRADE_MAX_RECORDS,
|
|
45
45
|
GRADE_MAX_WINDOW_DAYS,
|
|
46
|
+
JUSTIFICATION_ACCOUNT_GROUP,
|
|
46
47
|
MESSAGE_MAX_CURSOR_IDS,
|
|
47
48
|
MODERN_RECIPIENT_OPERATIONS,
|
|
48
49
|
MODULE_UNAVAILABLE_PATH,
|
|
@@ -90,6 +91,7 @@ from librus_python_api.gateway_grades import (
|
|
|
90
91
|
)
|
|
91
92
|
from librus_python_api.grade_parsers import parse_final_grades
|
|
92
93
|
from librus_python_api.homework_range import HomeworkAccumulator
|
|
94
|
+
from librus_python_api.justifications import parse_justifications
|
|
93
95
|
from librus_python_api.lifecycle import join_owned
|
|
94
96
|
from librus_python_api.message_content import parse_message_content, validate_reference
|
|
95
97
|
from librus_python_api.messages import parse_messages
|
|
@@ -119,6 +121,7 @@ from librus_python_api.models import (
|
|
|
119
121
|
Homework,
|
|
120
122
|
HomeworkRangeRequest,
|
|
121
123
|
Identity,
|
|
124
|
+
Justifications,
|
|
122
125
|
LoginSubmission,
|
|
123
126
|
MessageAttachmentReference,
|
|
124
127
|
MessageContent,
|
|
@@ -207,7 +210,7 @@ from librus_python_api.notifications import (
|
|
|
207
210
|
)
|
|
208
211
|
from librus_python_api.parsers import (
|
|
209
212
|
is_logged_out_page,
|
|
210
|
-
|
|
213
|
+
parse_identity_record,
|
|
211
214
|
parse_login,
|
|
212
215
|
parse_profile,
|
|
213
216
|
)
|
|
@@ -475,6 +478,8 @@ class AccountClient:
|
|
|
475
478
|
self._cooldowns: dict[str, tuple[float, ErrorKind]] = {}
|
|
476
479
|
self._consuming_schedule = False
|
|
477
480
|
self._modern_account: ModernAccountData | None = None
|
|
481
|
+
# `Me.Account.GroupId` of the current session, None when unknown.
|
|
482
|
+
self._account_group: int | None = None
|
|
478
483
|
|
|
479
484
|
@property
|
|
480
485
|
def _transport(self) -> AccountTransport:
|
|
@@ -1390,6 +1395,11 @@ class AccountClient:
|
|
|
1390
1395
|
for group in result.records.corrections
|
|
1391
1396
|
if not visible.isdisjoint(group.grade_ids)
|
|
1392
1397
|
),
|
|
1398
|
+
tuple(
|
|
1399
|
+
replace(item, entries=entries)
|
|
1400
|
+
for item in result.records.behaviour_points
|
|
1401
|
+
if (entries := tuple(e for e in item.entries if within(e.day)))
|
|
1402
|
+
),
|
|
1393
1403
|
)
|
|
1394
1404
|
|
|
1395
1405
|
async def class_free_days(
|
|
@@ -1410,6 +1420,37 @@ class AccountClient:
|
|
|
1410
1420
|
|
|
1411
1421
|
return await self._read(("class_free_days",), fetch, budget, max_age_seconds)
|
|
1412
1422
|
|
|
1423
|
+
async def justifications(
|
|
1424
|
+
self,
|
|
1425
|
+
*,
|
|
1426
|
+
budget: RequestBudget | None = None,
|
|
1427
|
+
max_age_seconds: float = 0.0,
|
|
1428
|
+
) -> Justifications:
|
|
1429
|
+
"""Read the e-Justifications list in the window the page shows by default.
|
|
1430
|
+
|
|
1431
|
+
One GET with no filter: entries sent before `window_start` may exist
|
|
1432
|
+
and are not returned. Only a login whose identity reports the parent
|
|
1433
|
+
account group (`JUSTIFICATION_ACCOUNT_GROUP`) sends the request; any
|
|
1434
|
+
other or missing group fails as UNSUPPORTED_CAPABILITY without it,
|
|
1435
|
+
because the page ends a student login's session.
|
|
1436
|
+
"""
|
|
1437
|
+
|
|
1438
|
+
async def fetch(budget: RequestBudget, _: bool) -> Justifications:
|
|
1439
|
+
if self._account_group != JUSTIFICATION_ACCOUNT_GROUP:
|
|
1440
|
+
raise LibrusError(ErrorKind.UNSUPPORTED_CAPABILITY)
|
|
1441
|
+
start, end, items = await self._page(
|
|
1442
|
+
"justifications", budget, parse_justifications
|
|
1443
|
+
)
|
|
1444
|
+
return Justifications(
|
|
1445
|
+
self._session_identity(),
|
|
1446
|
+
start,
|
|
1447
|
+
end,
|
|
1448
|
+
items,
|
|
1449
|
+
self._observation("justifications"),
|
|
1450
|
+
)
|
|
1451
|
+
|
|
1452
|
+
return await self._read(("justifications",), fetch, budget, max_age_seconds)
|
|
1453
|
+
|
|
1413
1454
|
async def attendance(
|
|
1414
1455
|
self,
|
|
1415
1456
|
*,
|
|
@@ -2258,6 +2299,7 @@ class AccountClient:
|
|
|
2258
2299
|
|
|
2259
2300
|
def _invalidate(self) -> None:
|
|
2260
2301
|
self._identity = None
|
|
2302
|
+
self._account_group = None
|
|
2261
2303
|
self._modern_account = None
|
|
2262
2304
|
self._cache.clear()
|
|
2263
2305
|
self._metadata.clear()
|
|
@@ -2681,8 +2723,8 @@ class AccountClient:
|
|
|
2681
2723
|
)
|
|
2682
2724
|
|
|
2683
2725
|
async def _fetch_identity(self, budget: RequestBudget) -> Identity:
|
|
2684
|
-
owner, student = await self._page(
|
|
2685
|
-
"identity", budget,
|
|
2726
|
+
owner, student, group = await self._page(
|
|
2727
|
+
"identity", budget, parse_identity_record, content_type=JSON
|
|
2686
2728
|
)
|
|
2687
2729
|
credentials, previous = self._credentials, self._identity
|
|
2688
2730
|
changed = previous is not None and (owner.id, student.id) != (
|
|
@@ -2699,6 +2741,7 @@ class AccountClient:
|
|
|
2699
2741
|
if changed or unexpected:
|
|
2700
2742
|
self._invalidate()
|
|
2701
2743
|
raise LibrusError(ErrorKind.ACCESS_DENIED)
|
|
2744
|
+
self._account_group = group
|
|
2702
2745
|
return Identity(owner, student, self._observation("identity"))
|
|
2703
2746
|
|
|
2704
2747
|
async def _authenticate(self, budget: RequestBudget) -> None:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: librus-python-api
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.10.0
|
|
4
4
|
Summary: Independent bounded async Librus Synergia client
|
|
5
5
|
Project-URL: Repository, https://github.com/krzysztofbury/librus-python-api
|
|
6
6
|
Project-URL: Issues, https://github.com/krzysztofbury/librus-python-api/issues
|
|
@@ -42,7 +42,11 @@ private ACLs. Windows installations include `pywin32` and `tzdata` automatically
|
|
|
42
42
|
Network paths, reparse-point paths and unsafe storage permissions fail closed.
|
|
43
43
|
See [platform requirements](contracts/persistence.md#windows-disk-boundary-25).
|
|
44
44
|
|
|
45
|
-
**Status:** `1.
|
|
45
|
+
**Status:** `1.10.0` returns behaviour points as a typed value
|
|
46
|
+
(`GradeRecords.behaviour_points`), reads the e-Justifications list on parent
|
|
47
|
+
logins (`AccountClient.justifications()`) and checks the gateway grade
|
|
48
|
+
pagination member recorded live.
|
|
49
|
+
`1.9.0` gives every ordinary grade its stable Librus ID (`grade_id`)
|
|
46
50
|
and links a corrected grade to its corrections, as the all view brackets them
|
|
47
51
|
(`GradeRecords.corrections`, [grade corrections](API.md#grade-ids-and-corrections-190)).
|
|
48
52
|
`1.8.4` reads multi-line formative assessment text and repeated
|
|
@@ -72,7 +76,7 @@ See [limitations](#supported-features-and-limitations) below.
|
|
|
72
76
|
Install the exact release from PyPI after its gated publication completes:
|
|
73
77
|
|
|
74
78
|
```sh
|
|
75
|
-
python -m pip install librus-python-api==1.
|
|
79
|
+
python -m pip install librus-python-api==1.10.0
|
|
76
80
|
```
|
|
77
81
|
|
|
78
82
|
Pin the exact version qualified by your application. Before publication, use a
|
|
@@ -88,7 +92,7 @@ python -m pip install .
|
|
|
88
92
|
To install a locally built wheel instead:
|
|
89
93
|
|
|
90
94
|
```sh
|
|
91
|
-
python -m pip install ./dist/librus_python_api-1.
|
|
95
|
+
python -m pip install ./dist/librus_python_api-1.10.0-py3-none-any.whl
|
|
92
96
|
```
|
|
93
97
|
|
|
94
98
|
No console script or background process is installed: import the library in your
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
librus_python_api/__init__.py,sha256=
|
|
1
|
+
librus_python_api/__init__.py,sha256=Dxx3F1zlAYSVB36Oqg4DLhFAM9RnhvbKipfXFHtSIEQ,6846
|
|
2
2
|
librus_python_api/_notification_bootstrap.py,sha256=18nzH0doXBNaZXCz-_ckIvRrlHTWV5Mm1t5m2-5eYGI,4669
|
|
3
3
|
librus_python_api/_notification_codec.py,sha256=hU6G3zGJ5fR8wfPC6fV2OqBKs-7XpT9eRnKO3FGsTzY,13451
|
|
4
4
|
librus_python_api/_storage.py,sha256=M_6ZAzN4zs7laOdKJBRH1I2rvy3pgqYgC_MZtsd2xtM,15893
|
|
@@ -12,22 +12,23 @@ librus_python_api/budget.py,sha256=8fvqT7eIxyVX2P2OBG27XsYHk_HbtSS4lzuecYpHtgs,2
|
|
|
12
12
|
librus_python_api/checkpoint.py,sha256=QBmG9GtpyaGRaFq-FXuGA3yR1BjuMFN9V3RTvvi_FNQ,1930
|
|
13
13
|
librus_python_api/class_free_days.py,sha256=IwoCgr-9ZgEYYQ6717s4cDpyFzbosHMzESMabXJLGqA,2422
|
|
14
14
|
librus_python_api/completed_lessons.py,sha256=ngGfBD6K4B6dR4elPYvNRvp40Q-GlrhUsUKqBbYY1KE,10727
|
|
15
|
-
librus_python_api/config.py,sha256=
|
|
15
|
+
librus_python_api/config.py,sha256=D6xCiJZCjXmtB9VoasG83j5uxvlZyj9kCnZsaVUvsQA,65334
|
|
16
16
|
librus_python_api/detail_fields.py,sha256=vDDi5sV-e30-42SF0hwAUoldiZ5wvYtb1UlLt03lBHw,1708
|
|
17
|
-
librus_python_api/diagnostics.py,sha256=
|
|
17
|
+
librus_python_api/diagnostics.py,sha256=SFQ3Wq6JEFOEHjRKe0-8zcCeJ8c8Eq8lIkVk2_a8IKU,19126
|
|
18
18
|
librus_python_api/exceptions.py,sha256=x8_z5UTNmuRINTK4buLYiKdYcFA2w6GZP9ZXOL-OnRU,5531
|
|
19
19
|
librus_python_api/files.py,sha256=pQBsIJyfTOZDz83ZB-5fcd-nPMcxR1HJ155h4zTHmsA,9223
|
|
20
20
|
librus_python_api/formative_grades.py,sha256=VykwtGvViZVOJMwPH3Re1RTDCHMr1_m9_xHjZyaXDIQ,6452
|
|
21
|
-
librus_python_api/gateway_grades.py,sha256=
|
|
21
|
+
librus_python_api/gateway_grades.py,sha256=p8odP84zGlJwpSJyk9ukflVMRIWEHvJngYzsvr2gv0c,16464
|
|
22
22
|
librus_python_api/grade_parsers.py,sha256=ROfffkCP8yj5Q708TZdpp0PDTyVmoh6X7m0y2fyJcwg,11202
|
|
23
|
-
librus_python_api/grade_records.py,sha256=
|
|
23
|
+
librus_python_api/grade_records.py,sha256=Kt9zwqZNQMsIovNj2Qu9Y6oRGEqRXw-1T1X2PpkNbeY,31650
|
|
24
24
|
librus_python_api/homework_range.py,sha256=erYfvS6PhHU5XhnR6LkiLNy677hGVflY3UAuHOs-YUw,1663
|
|
25
|
-
librus_python_api/inspect_page.py,sha256
|
|
25
|
+
librus_python_api/inspect_page.py,sha256=uSFJRcEd5m36kqqP6kf2uowB4x2RGNqyfnmaakVzL94,5938
|
|
26
|
+
librus_python_api/justifications.py,sha256=ZzfeZR5TvYyArQ5Oqi6VM5JmBKS2lZok4UR7hc3dI4o,7799
|
|
26
27
|
librus_python_api/lifecycle.py,sha256=XzA5CEdZFo7iL5IMUrawnRvf2m9BFe0OseP-fpQFaAE,856
|
|
27
28
|
librus_python_api/markup.py,sha256=TzGt8pRed2n--BpxFtLY0eq1wzdOhvKhehS50uPBi1o,7935
|
|
28
29
|
librus_python_api/message_content.py,sha256=v_qoEAoaYS0_9MQBaj57i5XnC7pzv_HHWefgTt4CNyM,9043
|
|
29
30
|
librus_python_api/messages.py,sha256=K9F8XVs1SojfFpdxxLV8gx9E0g81YxEHjigDzLHmDCg,10230
|
|
30
|
-
librus_python_api/models.py,sha256=
|
|
31
|
+
librus_python_api/models.py,sha256=Eeg0tQhhcP5r6cfU3JpT7I9MZ1ybQR6RnklJ1mgOznI,47125
|
|
31
32
|
librus_python_api/modern_body.py,sha256=SocXJTyGm1Q_2owzh1PE1zcCB2kqZTz1KPJ2R4yMyoc,3895
|
|
32
33
|
librus_python_api/modern_mailbox.py,sha256=2jF9UnJZ5AF6dip-GrMcv_z2kSLpp87dIpVeXk9jMzA,20600
|
|
33
34
|
librus_python_api/modern_messages.py,sha256=qt2CXtrxCZQ-jTt0aQCD6ZaPAJQZXf0BxmvacPo9B0w,10653
|
|
@@ -35,7 +36,7 @@ librus_python_api/notification_models.py,sha256=4eLTAE9JzHhveoaWtZQwGBolmb87QUP5
|
|
|
35
36
|
librus_python_api/notification_persistence.py,sha256=8GYPbCVD0AecrC4IUXFkHkhNS-uGXkXzsuKxreTIk9I,49454
|
|
36
37
|
librus_python_api/notification_workflow.py,sha256=XpWNGWbRsqtpTJinPsw65bjnnEnNpm-qzn0QPxz43Xg,13009
|
|
37
38
|
librus_python_api/notifications.py,sha256=VbA8pqNG_19yYo9y7IqpGRmfEb4qDcvA5gBb1syGJKs,7806
|
|
38
|
-
librus_python_api/parsers.py,sha256=
|
|
39
|
+
librus_python_api/parsers.py,sha256=FxRZvGHjCgz_2z5B9_uCCO4WCK54c0fYk5UqgJ4r0sc,9442
|
|
39
40
|
librus_python_api/parsing.py,sha256=H71srw5yx-RFrAKZFgj-QFX-DIXZmhnGrDTmJhazCB8,1838
|
|
40
41
|
librus_python_api/persistence.py,sha256=F35yBRu6D8aYgdwKTpzVdqVTyiUaLQludUmyyskb3Vo,15529
|
|
41
42
|
librus_python_api/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -44,10 +45,10 @@ librus_python_api/scheduler.py,sha256=3JplYxqvQdFz3aKXcoQUJHE9s3FPw_xRhQ2CPNLuQm
|
|
|
44
45
|
librus_python_api/school_reads.py,sha256=YHta7DmhjS5vSa4Djq8pzp01-2jhVfGOo1Mnc738rV4,15209
|
|
45
46
|
librus_python_api/school_year_archive.py,sha256=D0A1ywMKgoYgvi-d70__SFreMGvMb_72870Akkbb_m8,15492
|
|
46
47
|
librus_python_api/sending.py,sha256=Nvvk2r-6D6Us53a2fH5GW9PcA6bWEfuOvy6c3M5QVcE,4549
|
|
47
|
-
librus_python_api/service.py,sha256=
|
|
48
|
+
librus_python_api/service.py,sha256=N5ZtQHZGfLy7kOkMLN89cX2n3ILHeXu0bNJ8QCLtlLo,105340
|
|
48
49
|
librus_python_api/timetable.py,sha256=tX1QK9fQABxzfLaHHqTe8e6rAgdOkCoTOfAHdPwNmLE,9836
|
|
49
50
|
librus_python_api/transport.py,sha256=yF-DnFy4xGYS_RWQ9161b9WJXOlYF8cFRgdjXmVVUIk,34988
|
|
50
|
-
librus_python_api-1.
|
|
51
|
-
librus_python_api-1.
|
|
52
|
-
librus_python_api-1.
|
|
53
|
-
librus_python_api-1.
|
|
51
|
+
librus_python_api-1.10.0.dist-info/METADATA,sha256=zBKvJr0HX4wzTt2_Cb7YpGR2EVD4iz1V9vE4tGab0wo,15062
|
|
52
|
+
librus_python_api-1.10.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
53
|
+
librus_python_api-1.10.0.dist-info/licenses/LICENSE,sha256=IuerLb3cnZCsaB23znydjjvKqP-LmSJd3syKa9NGUts,1071
|
|
54
|
+
librus_python_api-1.10.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|