Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from urllib.request import urlopen
- print('**********************************************')
- print('PROGRAM: DISTRICT OLYMP DATA ANALYSIS')
- print('Enter year (!!!2015 or 2016 ONLY!!!): ', end = '')
- year = int(input())
- while year != 2015 and year != 2016:
- print('WRONG YEAR, TRY AGAIN: ', end = '')
- year = int(input())
- print('Enter your region: ', end = '')
- region = input()
- url = urlopen('http://reg.olimpiada.ru/district-olymp/public/winners/public.html?council={}&year={}'.format(region, year))
- data = url.read().decode('utf-8').split('\n')
- subj = []
- print('Enter your login: ', end = '')
- user_login = input()
- 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}
- data_students = []
- print('ALL STUDENTS RESULTS:')
- #названия предметов в переменной subj
- for line in data:
- if '{}&subject'.format(region) in line:
- start = 43
- finish = line.rfind('&')
- subj += [line[start:finish]]
- #список всех логинов в переменной data_students
- for subject in subj:
- url = urlopen('http://reg.olimpiada.ru/district-olymp/public/winners/public.html?council={}&subject={}&year={}'.format(region, subject, year))
- data = url.read().decode('utf-8').split('\n')
- for line in data:
- if 'sch77' in line:
- login = line[line.find('v'):line.find('v') + 11]
- if login not in data_students:
- data_students.append(login)
- max_score = 1
- #подсчет количества предметов, по которым ученик стал призером/победителем
- def student_score(login):
- global subj
- global results
- score = 0
- for subject in subj:
- url = urlopen('http://reg.olimpiada.ru/district-olymp/public/winners/public.html?council={}&subject={}&year={}'.format(region, subject, year))
- data = url.read().decode('utf-8').split('\n')
- for line in data:
- if login in line:
- score += 1
- if score > 0:
- results[score] += 1
- return score
- def student_subjects(login):
- global subj
- for subject in subj:
- url = urlopen('http://reg.olimpiada.ru/district-olymp/public/winners/public.html?council={}&subject={}&year={}'.format(region, subject, year))
- data = url.read().decode('utf-8').split('\n')
- subj_data = data[29]
- subj_res = subj_data[9:subj_data.find('&') - 1]
- for line in data:
- if login in line:
- print(subj_res)
- for login in data_students:
- score = student_score(login)
- print('>>>student: ', login,' >>>score: ', score)
- if score > max_score:
- max_score = score
- best_student = login
- print('STUDENTS:', len(data_students))
- for i in range(1, 12):
- if results[i] != 0:
- if i == 1:
- print(i, 'subject: ', results[i], 'students')
- else:
- print(i, 'subjects: ', results[i], 'students')
- print('BEST STUDENT: ', best_student, 'SCORE: ', max_score)
- login = best_student
- print('HIS/HER SUBJECTS:')
- student_subjects(login)
- print('Do you want to check your score?')
- print('>>> ', end = '')
- answer = input()
- if answer == 'yes':
- score = student_score(user_login)
- if score > 0:
- print('Your score:', score)
- print('Your subjects:')
- student_subjects(user_login)
- else:
- print("You haven't passed district tour")
- print('**********************************************')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement