kdzhr

Подсчёт баллов all

Mar 29th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.14 KB | None | 0 0
  1. import requests
  2.  
  3. login = input('Login:')
  4. password = input('Password:')
  5.  
  6. score_dict = {'classwork': 0, 'homework': 0, 'additional': 0}
  7. score_dict_all = {'classwork': 0, 'homework': 0, 'additional': 0}
  8.  
  9.  
  10. s = requests.Session()
  11. auth = s.post('https://passport.yandex.ru/passport?mode=auth',
  12.               data={'login': login, 'passwd': password})
  13. if auth.url == 'https://passport.yandex.ru/profile':
  14.     print('Авторизация прошла успешно')
  15.     print('--------------------------')
  16. else:
  17.     if 'Неправильный' in auth.text:
  18.         raise Exception('Неправильные логин или пароль')
  19.     raise Exception('Ошибка X')
  20.  
  21. courses_url = r'https://lyceum.yandex.ru/api/profile'
  22. courses = s.get(url=courses_url, params={'onlyActiveCourses': True,
  23.                                          'withCoursesSummary': True,
  24.                                          'withExpelled': True}).json()['coursesSummary'][
  25.     'student']
  26.  
  27. course_id = courses[1]['id']
  28. group_id = courses[1]['group']['id']
  29.  
  30. lessons = s.get(url='https://lyceum.yandex.ru/api/student/lessons',
  31.                 params={'courseId': course_id, 'groupId': group_id}).json()
  32. for lesson in lessons:
  33.     lesson_id = lesson['id']
  34.     lesson_tasks = s.get('https://lyceum.yandex.ru/api/student/lessonTasks',
  35.                          params={'courseId': course_id, 'lessonId': lesson_id}).json()
  36.     for tasks_group in lesson_tasks:
  37.         for task in tasks_group['tasks']:
  38.             sol = task['solution']
  39.             if sol:
  40.                 if sol['status']['type'] == 'review':
  41.                     score_dict[task['tag']['type']] += task['scoreMax']
  42.  
  43.             score_dict_all[task['tag']['type']] = score_dict_all.get(task['tag']['type'], 0) + task['scoreMax']
  44.  
  45. k = len(str(
  46.     max([score_dict['classwork'], score_dict['homework'], score_dict['additional']], key=lambda s: len(str(s)))))
  47. rating = courses[1]['rating']
  48. rating_all = score_dict_all['classwork'] / 100 * 0.3 + score_dict_all['homework'] / 100 * 0.3 + score_dict_all[
  49.     'additional'] / 100 * 1.2 + score_dict_all['individual-work'] * 0.1 + score_dict_all['control-work'] * 0.2
  50. impulse_score = score_dict['classwork'] / 100 * 0.3 + score_dict['homework'] / 100 * 0.3 + score_dict[
  51.     'additional'] / 100 * 1.2
  52. print('Классные задачи:       ', score_dict['classwork'], ' ' * (k - len(str(score_dict['classwork']))),
  53.       score_dict['classwork'] / 100 * 0.3)
  54. print('Домашние задачи:       ', score_dict['homework'], ' ' * (k - len(str(score_dict['homework']))),
  55.       score_dict['homework'] / 100 * 0.3)
  56. print('Дополнительные задачи:', score_dict['additional'], ' ' * (k - len(str(score_dict['additional']))),
  57.       score_dict['additional'] / 100 * 1.2)
  58. print('--------------------------')
  59. print('Баллы без проверки:', round(rating, 2))
  60. print('Баллы для проверки:', impulse_score)
  61. print('Баллы с проверкой: ', round(rating + impulse_score, 2))
  62. print(score_dict_all)
  63. print('Возможные баллы с проверкой: ', round(rating_all, 2))
  64. input('Жмякай Enter')
Add Comment
Please, Sign In to add comment