View difference between Paste ID: Qq00v87B and MjXDE1uF
SHOW: | | - or go back to the newest paste.
1
#!/usr/bin/env python
2
# coding=utf-8
3
import urllib.request, urllib.parse
4
import re
5
6
faculty = int(input('Номер факультета: '))
7
8
9
class Spec():
10
	def __init__(self, name, priority):
11
		self.name = name
12
		self.priority = priority
13
14
		
15
16
class Abt():
17
	def __init__(self, name, mark, ob, doc, spec):
18
		self.specs = []
19
		self.name = name
20
		self.mark = mark
21
		self.addSpec(spec)
22
		self.ob = ob
23
		self.doc = doc
24
		self.spec = spec
25
	def addSpec(self, spec):
26
		self.specs.append(spec)
27
		sorted = False
28
		while not sorted:
29
			sorted = True
30
			for i in range(len(self.specs) - 1):
31
				if self.specs[i].priority > self.specs[i+1].priority:
32
					sorted = False
33
					self.specs[i], self.specs[i+1] = self.specs[i+1], self.specs[i]
34
35
36
abts = []
37
38
def sortAbts():
39
	sorted = False
40
	while not sorted:
41
		sorted = True
42
		for i in range(len(abts) - 1):
43
			if abts[i].mark < abts[i+1].mark:
44
				sorted = False
45
				abts[i], abts[i+1] = abts[i+1], abts[i]
46
47
48
def addAbt(abt):
49
	for i in abts:
50
		if abt.name == i.name:
51
			i.addSpec(abt.spec)
52
			return
53
	abts.append(abt)
54
55
56
def printList(abts, mx):
57
	for i in range(mx):
58
		if len(abts) > i:
59
			print(str(i + 1) + ". " + abts[i].name + "\t\t" + abts[i].mark + "  " + abts[i].ob)
60
		else:
61
			print(str(i + 1) + ". <Пусто>")
62
63
def getList(spec):
64
65
	print ('Parse: ' + spec.name)
66
	opt = urllib.parse.urlencode({'budjet':'Б', 'form': 'О', 'dep': str(faculty), 'spec' : spec.name, 'listtype':'2', 'submit': 'Показать'})
67
	opt = opt.encode('utf-8')
68
	page = urllib.request.urlopen('http://priem.mai.ru/lists/', opt)
69
	page = page.read().decode('utf-8')
70
71
	maxAbitur = re.findall('<h2>Осталось мест: <span class="darkred">(.+?)</span>', page)
72
73
	if len(maxAbitur) != 0:
74
		spec.maxAbt = int(maxAbitur[0])
75
76
	page = page.replace('<nobr>','').replace('</nobr>','').replace('<br/>', ' ').replace('<td></td>','<td> </td>')
77
	ege = re.findall('<td>(.+?)</td>', page)
78
	del ege [0:11:1], ege [-4::1] # удаляем мусор
79
	# разбиваем на несколько списков
80
	names = ege[2::7] #имена
81
	marks = ege[4::7] # баллы (приоритет)
82
	obs = ege[3::7] # общежитие
83
	docs = ege[5::7] # тип документа
84
	abts = []
85
	for i in range(len(names)):
86
		if docs[i] != 'Копия' and docs[i] != 'Забрал документы':
87
			spc = Spec(spec.name, marks[i][5])
88
			ob = obs[i].replace('&nbsp;', '')
89
			abt = Abt(names[i], marks[i][0:3], ob, docs[i], spc)
90
			addAbt(abt)
91
92
93
class SpecListSegment():
94
	def __init__(self, name, maxAbt):
95
		self.name = name
96
		self.maxAbt = maxAbt
97
98
specList = []
99
100
page = urllib.request.urlopen('http://priem.mai.ru/lists/')
101
page = page.read().decode('utf-8')
102
matches = re.findall('<option class="' + str(faculty) + '" value="(.+?)" >',page)
103
104
105
for i in matches:
106
	specList.append(SpecListSegment(i, 0))
107
108
109
110
for i in specList:
111
	getList(i)
112
113
114
sortAbts()
115
116
117
118
outList = []
119
120
for i in range(len(specList)):
121
	outList.append([])
122
123
def check(j):
124
	for i in range(len(specList)):
125
		if specList[i].name == j.name:
126
			if len(outList[i]) < specList[i].maxAbt:
127
				return i
128
			else:
129
				return -1
130
131
132
133
for i in abts:
134
	for j in i.specs:
135
		a = check(j)
136
		if a != -1:
137
			outList[a].append(i)
138
			break
139
140
141
print("\nСписки:")
142
for i in range(len(outList)):
143
	print(specList[i].name)
144-
	printList(outList[i], specList[i].maxAbt)
144+
	printList(outList[i], specList[i].maxAbt)
145
	print()