matplobbot-shared 0.1.38__py3-none-any.whl → 0.1.41__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.
Potentially problematic release.
This version of matplobbot-shared might be problematic. Click here for more details.
- {matplobbot_shared-0.1.38.dist-info → matplobbot_shared-0.1.41.dist-info}/METADATA +1 -1
- {matplobbot_shared-0.1.38.dist-info → matplobbot_shared-0.1.41.dist-info}/RECORD +5 -5
- shared_lib/services/schedule_service.py +48 -1
- {matplobbot_shared-0.1.38.dist-info → matplobbot_shared-0.1.41.dist-info}/WHEEL +0 -0
- {matplobbot_shared-0.1.38.dist-info → matplobbot_shared-0.1.41.dist-info}/top_level.txt +0 -0
|
@@ -3,9 +3,9 @@ shared_lib/database.py,sha256=lEIqM8e68RH8BCGVKk8dbZ-8JYIVB7c6l8AfhNPbYfg,21877
|
|
|
3
3
|
shared_lib/i18n.py,sha256=VBWQWVF-k_HDiidYo_RUPyUCM7oL897z5hOw9jvOoYY,1762
|
|
4
4
|
shared_lib/redis_client.py,sha256=j7AKwrSWhtEHeV25Sy0JiWLIx2EI3hFEx7suoOwxRU8,2234
|
|
5
5
|
shared_lib/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
shared_lib/services/schedule_service.py,sha256=
|
|
6
|
+
shared_lib/services/schedule_service.py,sha256=WYBHnBsxdE5zR6ajhatKnqYM9icUYA9_s6PpjCZtBpU,7173
|
|
7
7
|
shared_lib/services/university_api.py,sha256=Ui-zjfKOHCCf2Imh8CNtVOWegwuep7IB8gO9IKNUrrE,1898
|
|
8
|
-
matplobbot_shared-0.1.
|
|
9
|
-
matplobbot_shared-0.1.
|
|
10
|
-
matplobbot_shared-0.1.
|
|
11
|
-
matplobbot_shared-0.1.
|
|
8
|
+
matplobbot_shared-0.1.41.dist-info/METADATA,sha256=20GzrBiTw-okL15hogJl7JPXXTGTB1L12Ze_hA1WXn0,416
|
|
9
|
+
matplobbot_shared-0.1.41.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
10
|
+
matplobbot_shared-0.1.41.dist-info/top_level.txt,sha256=L8mrC50YWCe19jmh_zrUZFvXSkhsnES5K6y027G1838,11
|
|
11
|
+
matplobbot_shared-0.1.41.dist-info/RECORD,,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# bot/services/schedule_service.py
|
|
2
2
|
|
|
3
3
|
from typing import List, Dict, Any
|
|
4
|
-
from datetime import datetime, date
|
|
4
|
+
from datetime import datetime, date
|
|
5
5
|
from collections import defaultdict
|
|
6
6
|
from ics import Calendar, Event
|
|
7
7
|
from zoneinfo import ZoneInfo
|
|
@@ -18,6 +18,53 @@ to_add = {
|
|
|
18
18
|
}
|
|
19
19
|
names_shorter.update(to_add)
|
|
20
20
|
|
|
21
|
+
def _format_lesson_for_diff(lesson: Dict[str, Any], lang: str) -> str:
|
|
22
|
+
"""Formats a single lesson for display in a diff message."""
|
|
23
|
+
date_obj = datetime.strptime(lesson['date'], "%Y-%m-%d").date()
|
|
24
|
+
day_header = f"<b>{date_obj.strftime('%A, %d.%m.%Y')}</b>"
|
|
25
|
+
details = [
|
|
26
|
+
hcode(f"{lesson['beginLesson']} - {lesson['endLesson']} | {lesson['auditorium']}"),
|
|
27
|
+
f"{lesson['discipline']} ({names_shorter[lesson['kindOfWork']]})",
|
|
28
|
+
f"<i>{translator.gettext(lang, 'lecturer_prefix')}: {lesson.get('lecturer_title', 'N/A').replace('_', ' ')}</i>"
|
|
29
|
+
]
|
|
30
|
+
return f"{day_header}\n" + "\n".join(details)
|
|
31
|
+
|
|
32
|
+
def diff_schedules(old_data: List[Dict[str, Any]], new_data: List[Dict[str, Any]], lang: str) -> str | None:
|
|
33
|
+
"""Compares two schedule datasets and returns a human-readable diff."""
|
|
34
|
+
old_lessons = {lesson['lessonOid']: lesson for lesson in old_data}
|
|
35
|
+
new_lessons = {lesson['lessonOid']: lesson for lesson in new_data}
|
|
36
|
+
|
|
37
|
+
added = [lesson for oid, lesson in new_lessons.items() if oid not in old_lessons]
|
|
38
|
+
removed = [lesson for oid, lesson in old_lessons.items() if oid not in new_lessons]
|
|
39
|
+
modified = []
|
|
40
|
+
|
|
41
|
+
# Fields to check for modifications
|
|
42
|
+
fields_to_check = ['beginLesson', 'endLesson', 'auditorium', 'lecturer_title']
|
|
43
|
+
|
|
44
|
+
for oid, old_lesson in old_lessons.items():
|
|
45
|
+
if oid in new_lessons:
|
|
46
|
+
new_lesson = new_lessons[oid]
|
|
47
|
+
changes = {}
|
|
48
|
+
for field in fields_to_check:
|
|
49
|
+
if old_lesson.get(field) != new_lesson.get(field):
|
|
50
|
+
changes[field] = (old_lesson.get(field), new_lesson.get(field))
|
|
51
|
+
if changes:
|
|
52
|
+
modified.append({'new': new_lesson, 'changes': changes})
|
|
53
|
+
|
|
54
|
+
if not added and not removed and not modified:
|
|
55
|
+
return None
|
|
56
|
+
|
|
57
|
+
diff_parts = []
|
|
58
|
+
if added: diff_parts.append(f"<b>{translator.gettext(lang, 'schedule_change_added')}:</b>\n" + "\n\n".join([_format_lesson_for_diff(l, lang) for l in added]))
|
|
59
|
+
if removed: diff_parts.append(f"<b>{translator.gettext(lang, 'schedule_change_removed')}:</b>\n" + "\n\n".join([_format_lesson_for_diff(l, lang) for l in removed]))
|
|
60
|
+
if modified:
|
|
61
|
+
modified_texts = []
|
|
62
|
+
for mod in modified:
|
|
63
|
+
change_descs = [f"<i>{translator.gettext(lang, f'field_{f}')}: {hcode(v[0])} → {hcode(v[1])}</i>" for f, v in mod['changes'].items()]
|
|
64
|
+
modified_texts.append(f"{_format_lesson_for_diff(mod['new'], lang)}\n" + "\n".join(change_descs))
|
|
65
|
+
diff_parts.append(f"<b>{translator.gettext(lang, 'schedule_change_modified')}:</b>\n" + "\n\n".join(modified_texts))
|
|
66
|
+
|
|
67
|
+
return "\n\n---\n\n".join(diff_parts)
|
|
21
68
|
|
|
22
69
|
|
|
23
70
|
def format_schedule(schedule_data: List[Dict[str, Any]], lang: str, entity_name: str, entity_type: str, start_date: date, is_week_view: bool = False) -> str:
|
|
File without changes
|
|
File without changes
|