Created
August 1, 2011 15:32
-
-
Save lomereiter/1118353 to your computer and use it in GitHub Desktop.
script for spbu applicants
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from urllib2 import urlopen | |
import re | |
import time | |
class DegreeProgramInfo: | |
regexp = re.compile( | |
r"\d</td>\s*<td>\s*(\d+)</td>\s*(?:<td>[^<]*</td>\s*){5}<td>([^<]+)</td>", | |
re.MULTILINE | re.UNICODE) | |
def __init__(self, id, name, url, places): | |
self.id, self.name, self.places = id, name, places | |
self.url = 'https://priem2011.spbu.ru/templates/firstwaveentrylists/' \ | |
+ url | |
def update(self): | |
page = urlopen(self.url).read() | |
self.free, self.position = self.places, 1 | |
for match in DegreeProgramInfo.regexp.finditer( | |
page.decode('cp1251').encode('utf-8')): | |
id, status = int(match.group(1)), match.group(2).strip() | |
if id == self.id: | |
break | |
if status == 'Да': | |
self.free -= 1 | |
if status != 'Забрал Документы': | |
self.position += 1 | |
ID = 114134 | |
UPDATE_INTERVAL = 900 | |
matobes = DegreeProgramInfo(ID, 'Матобес', 'list1_1_1_17_5_.html', 75) | |
primat = DegreeProgramInfo(ID, 'Примат', 'list1_1_1_15_4_.html', 75) | |
pm_pu = DegreeProgramInfo(ID, 'ПМ-ПУ', 'list1_1_1_16_4_.html', 180) | |
PROGRAMS = [matobes, primat, pm_pu] | |
while True: | |
for program in PROGRAMS: | |
program.update() | |
print("%s: free - %d, position - %d; " % | |
(program.name, program.free, program.position)), | |
if program.position <= program.places: | |
print('welcome!') | |
elif program.free <= 0: | |
print('fuck!') | |
else: | |
time.sleep(UPDATE_INTERVAL) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment