Advertisement
kdzhr

LMS_Ultimate_Checker

Apr 6th, 2020
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.58 KB | None | 0 0
  1. # supported by @plus_31, @forbidden____403, @konst_ph
  2.  
  3. import requests
  4. from collections import defaultdict
  5. import sys
  6.  
  7. assert sys.version_info >= (3, 8), "Нужен Python 3.8 или выше!"
  8. print('Для корректного вычисления рейтинга должны быть открыты все уроки!')
  9. login = input('Login: ')
  10. password = input('Password: ')
  11.  
  12. primary_points_unchecked = defaultdict(int)
  13. primary_points_all = defaultdict(int)
  14.  
  15. s = requests.Session()
  16. auth = s.post(
  17.     'https://passport.yandex.ru/passport?mode=auth',
  18.     data={'login': login, 'passwd': password}
  19. )
  20. if auth.url == 'https://passport.yandex.ru/profile':
  21.     print('Авторизация прошла успешно')
  22.     print('--------------------------')
  23. else:
  24.     if 'Неправильный' in auth.text:
  25.         raise Exception('Неправильные логин или пароль')
  26.     raise Exception('Неизвестная ошибка авторизации')
  27.  
  28. courses = s.get(
  29.     url='https://lyceum.yandex.ru/api/profile',
  30.     params={
  31.         'onlyActiveCourses': True,
  32.         'withCoursesSummary': True,
  33.         'withExpelled': True
  34.     }
  35. ).json()['coursesSummary']['student']
  36.  
  37. for c in courses:
  38.     if 'Основы программирования на языке Python' in c['title']:
  39.         course = c
  40.         break
  41. else:
  42.     raise Exception('Курс не найден')
  43.  
  44. course_id = course['id']
  45. group_id = course['group']['id']
  46.  
  47. lessons = s.get(
  48.     url='https://lyceum.yandex.ru/api/student/lessons',
  49.     params={'courseId': course_id, 'groupId': group_id}
  50. ).json()
  51.  
  52. lessons_with_work_type = defaultdict(int)
  53. count_of_points = defaultdict(int)
  54. count_of_tasks = defaultdict(int)
  55.  
  56. for lesson in lessons:
  57.     lesson_id = lesson['id']
  58.     tasks_groups = s.get(
  59.         'https://lyceum.yandex.ru/api/student/lessonTasks',
  60.         params={'courseId': course_id, 'lessonId': lesson_id}
  61.     ).json()
  62.     for tasks_group in tasks_groups:
  63.         lessons_with_work_type[tasks_group['type']] += 1
  64.         for task in tasks_group['tasks']:
  65.             if (sol := task['solution']) and sol['status']['type'] == 'review':
  66.                 primary_points_unchecked[task['tag']['type']] += task['scoreMax']
  67.             primary_points_all[task['tag']['type']] += task['scoreMax']
  68.             count_of_points[task['tag']['type']] += task['scoreMax']
  69.             count_of_tasks[task['tag']['type']] += 1
  70.  
  71. rating = course['rating']
  72.  
  73. rating_all = (primary_points_all['classwork'] / 100) * (10 / lessons_with_work_type['classwork']) \
  74.              + (primary_points_all['homework'] / 100) * (10 / lessons_with_work_type['homework']) \
  75.              + (primary_points_all['additional'] / 100) * (40 / lessons_with_work_type['additional']) \
  76.              + (primary_points_all['individual-work'] / 100) * (20 / lessons_with_work_type['individual-work']) \
  77.              + (primary_points_all['control-work'] / 100) * (40 / lessons_with_work_type['control-work'])
  78.  
  79. classwork_score_unchecked = (primary_points_unchecked['classwork'] / 100) * (10 / lessons_with_work_type['classwork'])
  80. homework_score_unchecked = (primary_points_unchecked['homework'] / 100) * (10 / lessons_with_work_type['homework'])
  81. additional_score_unchecked = (primary_points_unchecked['additional'] / 100) * (
  82.             40 / lessons_with_work_type['additional'])
  83.  
  84. impulse_score = classwork_score_unchecked + homework_score_unchecked + additional_score_unchecked
  85.  
  86. print('Непроверенные задачи:')
  87. print(f"Классные задачи:       {primary_points_unchecked['classwork']:.2f} {classwork_score_unchecked:.2f}")
  88. print(f"Домашние задачи:       {primary_points_unchecked['homework']:.2f} {homework_score_unchecked:.2f}")
  89. print(f"Дополнительные задачи: {primary_points_unchecked['additional']:.2f} {additional_score_unchecked:.2f}")
  90.  
  91. print('--------------------------')
  92.  
  93. print(f'Баллы без проверки: {rating:.2f}')
  94. print(f'Баллы для проверки: {impulse_score:.2f}')
  95. print(f'Баллы с проверкой:  {rating + impulse_score:.2f}')
  96. print(dict(primary_points_all))
  97. print(f'Возможные баллы с проверкой: {rating_all:.2f}')
  98.  
  99. print('Общее количество задач в категориях:')
  100. for key, value in count_of_tasks.items():
  101.     print(f'Тэг {key}: {value}')
  102.  
  103. print('Общее количество первичных баллов в категориях:')
  104. for key, value in count_of_points.items():
  105.     print(f'Тэг {key}: {value}')
  106.  
  107. input('Жмякай Enter')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement