-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsearch.py
57 lines (46 loc) · 2.05 KB
/
search.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
55
56
57
from methods import *
def search_tasks(lessons, search_part):
found = []
search_part = search_part.lower()
for lesson_title, tasks in lessons:
for tasks_group in tasks:
for task in tasks_group['tasks']:
task_title = task['title']
if search_part in task_title.lower():
sol = task['solution']
if not sol:
found.append((lesson_title, task_title, False))
else:
found.append((lesson_title, task_title, bool(sol['score'])))
return found
def prepare(s, course_id, group_id):
lessons = []
print("Получаю информацию об уроках, это занимает примерно 5-10 секунд...")
lessons_info = get_all_lessons(s, course_id, group_id)
for lesson in lessons_info:
lesson_title = lesson['title']
lesson_id = lesson['id']
tasks = get_all_tasks(s, lesson_id, course_id)
lessons.append([lesson_title, tasks])
print("Закончил")
print("===========\n")
return lessons
if __name__ == '__main__':
s = get_and_auth()
course_id, group_id = get_course(s)
lessons = prepare(s, course_id, group_id)
print(r'Для остановки ввода введите \\')
print("Часть названия задачи, которую нужно найти: ")
search_part = input()
while search_part != r'\\':
fd = search_tasks(lessons, search_part)
if not fd:
print('Не удалось найти задачу')
else:
for lesson_name, task_title_full, is_solved in fd:
print(f'Урок: "{lesson_name}", Задача: "{task_title_full}" '
f'({"" if is_solved else "не"} решена)')
print('===========\n')
print(r'Для остановки ввода введите \\')
print("Часть названия задачи, которую нужно найти: ")
search_part = input()