Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # coding=utf-8
- import re
- import twitter
- import urllib
- # отрезаем ненужный тег nobr
- def strip_nobr(string):
- return string[6:len(string) - 7]
- # конвертируем вне-конкурсниов в 300 баллов для более удобной работы
- def convert_marks(match):
- if match[5] == 'Без экзаменов':
- return 300
- elif match[5] == 'Вне конкурса':
- return 300
- else:
- return int(match[4][0:3])
- # настройки
- my_mark = 214 # ваш балл
- twitter_login = 'ha-ha' # логин в твиттере
- twitter_password = 'ha-ha' # пасс там же
- # main
- params = urllib.urlencode({'dep': '8', 'form': 'О', 'listtype': '2', 'spec': '1', 'submit': 'Показать'})
- page = urllib.urlopen('http://priem.mai.ru/clists/', params).read().replace('\n', '').replace('\r', '')
- matches = re.compile('<tr><td>([0-9]+)</td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td></tr>').findall(page)
- # Счётчики
- counter_better = 0
- counter_with_hostel = 0
- counter_without_hostel = 0
- # Проходные баллы
- mark_with_hostel = 300
- mark_without_hostel = 300
- # id
- with_hostel = []
- without_hostel = []
- # Считаем
- for i in range(len(matches)):
- match = matches[i]
- mark = convert_marks(match)
- if match[6] == 'Подлинник':
- if (counter_with_hostel + counter_without_hostel < 111): # всего 111 мест на зачисление: 20 с общежитием, 91 без
- if counter_with_hostel < 20: # места в общежитии ещё есть
- if (match[8] == 'Общежитие' and match[3] != 'Без общежития'): # человеку нужно общежитие
- counter_with_hostel += 1
- mark_with_hostel = mark
- with_hostel.append(i)
- else: # человеку совсем не нужно общежитие
- counter_without_hostel += 1
- mark_without_hostel = mark
- without_hostel.append(i)
- if mark > my_mark:
- counter_better += 1
- else: # места в общежитии закончились
- if (match[8] == ' ' or (match[8] == 'Общежитие' and match[9] == 'Согласен')): # человеку не нужно общежитие или он согласен и без него
- counter_without_hostel +=1
- mark_without_hostel = mark
- without_hostel.append(i)
- if mark > my_mark:
- counter_better += 1
- # Пишем в твиттер
- counter_all = counter_with_hostel + counter_without_hostel
- msg = ('MAI-8: {0}/111 ; {1}/{2}/{3} ; {4}/{5}').format(counter_better, counter_with_hostel, counter_without_hostel, counter_all, mark_without_hostel, mark_with_hostel)
- twitter.Api(twitter_login, twitter_password).PostUpdate(msg)
- # Выводим результаты
- print 'Проходят с общежитием:'
- for i in range(len(with_hostel)):
- match = matches[with_hostel[i]]
- mark = convert_marks(match)
- print ('{0}) {1} ({2})').format(i + 1, strip_nobr(match[2]), mark)
- print '\r\nПроходят без общежития:'
- for i in range(len(without_hostel)):
- match = matches[without_hostel[i]]
- mark = convert_marks(match)
- print ('{0}) {1} ({2})').format(i + 1, strip_nobr(match[2]), mark)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement