Advertisement
575

analysis olymp data

575
Jan 2nd, 2017
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.53 KB | None | 0 0
  1. from urllib.request import urlopen
  2.  
  3.  
  4. print('**********************************************')
  5.  
  6. print('PROGRAM: DISTRICT OLYMP DATA ANALYSIS')
  7.  
  8. print('Enter year (!!!2015 or 2016 ONLY!!!): ', end = '')
  9. year = int(input())
  10. while year != 2015 and year != 2016:
  11.     print('WRONG YEAR, TRY AGAIN: ', end = '')
  12.     year = int(input())
  13.  
  14. print('Enter your region: ', end = '')
  15. region = input()
  16.  
  17. url = urlopen('http://reg.olimpiada.ru/district-olymp/public/winners/public.html?council={}&year={}'.format(region, year))
  18. data = url.read().decode('utf-8').split('\n')
  19. subj = []
  20.  
  21. print('Enter your login: ', end = '')
  22. user_login = input()
  23.  
  24. results = {1: 0, 2: 0, 3: 0, 4: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0, 10: 0, 11: 0}
  25. data_students = []
  26.  
  27. print('ALL STUDENTS RESULTS:')
  28. #названия предметов в переменной subj
  29. for line in data:
  30.     if '{}&subject'.format(region) in line:
  31.         start = 43
  32.  
  33.         finish = line.rfind('&')
  34.         subj += [line[start:finish]]
  35.  
  36.  
  37. #список всех логинов в переменной data_students
  38. for subject in subj:
  39.     url = urlopen('http://reg.olimpiada.ru/district-olymp/public/winners/public.html?council={}&subject={}&year={}'.format(region, subject, year))
  40.     data = url.read().decode('utf-8').split('\n')
  41.     for line in data:
  42.         if 'sch77' in line:
  43.             login = line[line.find('v'):line.find('v') + 11]
  44.             if login not in data_students:
  45.                 data_students.append(login)
  46.                
  47. max_score = 1
  48.  
  49. #подсчет количества предметов, по которым ученик стал призером/победителем
  50. def student_score(login):
  51.     global subj
  52.     global results
  53.     score = 0
  54.     for subject in subj:
  55.         url = urlopen('http://reg.olimpiada.ru/district-olymp/public/winners/public.html?council={}&subject={}&year={}'.format(region, subject, year))
  56.         data = url.read().decode('utf-8').split('\n')
  57.  
  58.         for line in data:
  59.             if login in line:
  60.                 score += 1
  61.     if score > 0:
  62.         results[score] += 1
  63.     return score
  64.  
  65.  
  66. def student_subjects(login):
  67.     global subj
  68.     for subject in subj:
  69.         url = urlopen('http://reg.olimpiada.ru/district-olymp/public/winners/public.html?council={}&subject={}&year={}'.format(region, subject, year))
  70.         data = url.read().decode('utf-8').split('\n')
  71.         subj_data = data[29]
  72.         subj_res = subj_data[9:subj_data.find('&') - 1]
  73.         for line in data:
  74.             if login in line:
  75.                 print(subj_res)
  76.  
  77.  
  78. for login in data_students:
  79.     score = student_score(login)
  80.     print('>>>student: ', login,' >>>score: ', score)
  81.     if score > max_score:
  82.         max_score = score
  83.         best_student = login
  84.  
  85.  
  86. print('STUDENTS:', len(data_students))
  87. for i in range(1, 12):
  88.     if results[i] != 0:
  89.         if i == 1:
  90.             print(i, 'subject: ', results[i], 'students')
  91.         else:
  92.             print(i, 'subjects: ', results[i], 'students')
  93.  
  94. print('BEST STUDENT: ', best_student, 'SCORE: ', max_score)
  95. login = best_student
  96. print('HIS/HER SUBJECTS:')
  97. student_subjects(login)
  98.  
  99.  
  100. print('Do you want to check your score?')
  101. print('>>> ', end = '')
  102. answer = input()
  103. if answer == 'yes':
  104.     score = student_score(user_login)
  105.     if score > 0:
  106.         print('Your score:', score)
  107.         print('Your subjects:')
  108.         student_subjects(user_login)
  109.     else:
  110.         print("You haven't passed district tour")
  111.  
  112.  
  113. print('**********************************************')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement