-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecoder.py
56 lines (41 loc) · 1.8 KB
/
decoder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from typing import List, Dict
from design.HtmlDecorator import bold, bold_underline
from vo.Day import Day
from vo.Lesson import Lesson
def group_lessons_by_day(array: [str]) -> Dict[str, Day]:
groups: Dict[str, Day] = {}
for item in array:
lesson = Lesson(item['title'],
item['start'],
item['start'],
item['end'],
item['FacultyName'],
item['RoomNo'])
key = lesson.get_key()
try:
groups[key].append_lesson(lesson)
except KeyError:
lessons = [lesson]
day = Day(item['start'], lessons)
groups.update({key: day})
return groups
def format_schedule_message(groups: Dict[str, Day]) -> List[str]:
list_of_lessons: List[str] = []
for key, day in groups.items():
one_day = [bold_underline(f'{day.get_short_date()} — {day.get_weekday()}\n')]
for lesson in day.get_lessons():
one_day.append(
f'{bold(lesson.get_short_start_time())} {lesson.get_title()}')
list_of_lessons.append('\n'.join(one_day))
return list_of_lessons
def format_schedule_message_with_add_info(groups: Dict[str, Day]) -> List[str]:
list_of_lessons: List[str] = []
for key, day in groups.items():
one_day = [bold_underline(f'{day.get_short_date()} — {day.get_weekday()}\n')]
for lesson in day.get_lessons():
one_day.append(
f'{bold(lesson.get_short_start_time())} {lesson.get_title()}\n'
f"{bold('RoomNo: ')}{lesson.get_room_no()}\n"
f"{bold('FacultyName: ')}{lesson.get_faculty_name()}\n")
list_of_lessons.append('\n'.join(one_day))
return list_of_lessons