Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2010
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.34 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # coding=utf-8
  3. import re
  4. import twitter
  5. import urllib
  6.  
  7. # отрезаем ненужный тег nobr
  8. def strip_nobr(string):
  9.     return string[6:len(string) - 7]
  10.    
  11. # конвертируем вне-конкурсниов в 300 баллов для более удобной работы
  12. def convert_marks(match):
  13.     if match[5] == 'Без экзаменов':
  14.         return 300
  15.     elif match[5] == 'Вне конкурса':
  16.         return 300
  17.     else:
  18.         return int(match[4][0:3])
  19.  
  20. # настройки
  21. my_mark = 214 # ваш балл
  22. twitter_login = 'ha-ha' # логин в твиттере
  23. twitter_password = 'ha-ha' # пасс там же
  24.  
  25. # main
  26. params = urllib.urlencode({'dep': '8', 'form': 'О', 'listtype': '2', 'spec': '1', 'submit': 'Показать'})
  27. page = urllib.urlopen('http://priem.mai.ru/clists/', params).read().replace('\n', '').replace('\r', '')
  28. 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)
  29.  
  30. # Счётчики
  31. counter_better = 0
  32.  
  33. counter_with_hostel = 0
  34. counter_without_hostel = 0
  35.  
  36. # Проходные баллы
  37. mark_with_hostel = 300
  38. mark_without_hostel = 300
  39.  
  40. # id
  41. with_hostel = []
  42. without_hostel = []
  43.  
  44. # Считаем
  45. for i in range(len(matches)):
  46.     match = matches[i]
  47.     mark = convert_marks(match)
  48.        
  49.     if match[6] == 'Подлинник':
  50.         if (counter_with_hostel + counter_without_hostel < 111): # всего 111 мест на зачисление: 20 с общежитием, 91 без
  51.             if counter_with_hostel < 20: # места в общежитии ещё есть
  52.                 if (match[8] == 'Общежитие' and match[3] != 'Без общежития'): # человеку нужно общежитие
  53.                     counter_with_hostel += 1
  54.                     mark_with_hostel = mark
  55.                     with_hostel.append(i)
  56.                 else: # человеку совсем не нужно общежитие
  57.                     counter_without_hostel += 1
  58.                     mark_without_hostel = mark
  59.                     without_hostel.append(i)
  60.                    
  61.                     if mark > my_mark:
  62.                         counter_better += 1
  63.             else: # места в общежитии закончились
  64.                 if (match[8] == '&nbsp;' or (match[8] == 'Общежитие' and match[9] == 'Согласен')): # человеку не нужно общежитие или он согласен и без него
  65.                     counter_without_hostel +=1
  66.                     mark_without_hostel = mark
  67.                     without_hostel.append(i)
  68.                    
  69.                     if mark > my_mark:
  70.                         counter_better += 1
  71.  
  72. # Пишем в твиттер
  73. counter_all = counter_with_hostel + counter_without_hostel
  74.    
  75. 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)
  76. twitter.Api(twitter_login, twitter_password).PostUpdate(msg)
  77.  
  78. # Выводим результаты
  79. print 'Проходят с общежитием:'
  80. for i in range(len(with_hostel)):
  81.     match = matches[with_hostel[i]]
  82.     mark = convert_marks(match)
  83.    
  84.     print ('{0}) {1} ({2})').format(i + 1, strip_nobr(match[2]), mark)
  85.    
  86. print '\r\nПроходят без общежития:'
  87. for i in range(len(without_hostel)):
  88.     match = matches[without_hostel[i]]
  89.     mark = convert_marks(match)
  90.    
  91.     print ('{0}) {1} ({2})').format(i + 1, strip_nobr(match[2]), mark)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement