-
Notifications
You must be signed in to change notification settings - Fork 1
/
results.py
128 lines (106 loc) · 2.83 KB
/
results.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import requests
from bs4 import BeautifulSoup as BS
import time
from sys import argv
script, filename = argv
def cmpcgpa(x, y):
if x[2] > y[2]:
return 1
else:
return -1
def cmpsgpa(x, y):
if x[1] > y[1]:
return 1
else:
return -1
url = 'http://117.211.91.61/web/Default.aspx/'
start = raw_input("Enter your year code (eg - EL112 if your roll no is EL112001):")
sem = raw_input("Enter sem:")
reglist = []
rolls = open(filename)
for roll in rolls.readlines():
reglist.append(roll)
ranklist = []
def getState(url, data=None, headers=None):
r = requests.post(url, data=data, headers=headers)
soup = BS(r.text)
state = soup.findAll(attrs={'name': '__VIEWSTATE'})[0]['value']
return state
i = 0
headers = {
'Host': '117.211.91.61',
'Connection': 'keep-alive',
'Content-Length': '377',
'Cache-Control': 'max-age=0',
'Accept': 'text/html,application/xhtml+xml,application/ xml;q=0.9,image/webp,*/*;q=0.8',
'Origin': 'http://117.211.91.61',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded',
'Referer': 'http://117.211.91.61/web/Default.aspx',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.8,hi;q=0.6'
}
post_data_page1 = {
"ToolkitScriptManager1_HiddenField": "",
"__EVENTTARGET": "",
"__EVENTARGUMENT": "",
"__VIEWSTATE": '',
'txtRegno': '',
'btnimgShow.x': '34',
'btnimgShow.y': '10'
}
post_data_page2 = {
"ToolkitScriptManager1_HiddenField": "",
"__EVENTTARGET": "",
"__EVENTARGUMENT": "",
"__VIEWSTATE": '',
'txtRegno': '',
'ddlSemester': '',
'btnimgShowResult.x': '25',
'btnimgShowResult.y': '11'
}
while i < len(reglist):
try:
current_state = getState(url)
except:
continue
post_data_page1['__VIEWSTATE'] = current_state
post_data_page1['txtRegno'] = start + str(reglist[i])
try:
state = getState(url, data=post_data_page1, headers=headers)
except:
continue
post_data_page2['__VIEWSTATE'] = state
post_data_page2['ddlSemester'] = sem
post_data_page2['txtRegno'] = start + reglist[i]
try:
s = requests.post(url, headers=headers, data=post_data_page2)
except:
continue
soup = BS(s.text)
try:
roll = str(soup.find(id="lblSRollNo").text)
cgpa = str(soup.find(id="lblCPI").text)
sgpa = str(soup.find(id="lblSPI").text)
except:
i += 1
continue
ranklist.append((roll, sgpa, cgpa))
time.sleep(2)#because the server appears to not respond if queries are made back-to-back without any delay
i += 1
ranklist.sort(cmp = cmpsgpa, reverse=True)
c = 1
print "SGPA Wise"
print "-" * 10
for item in ranklist:
print c, ".", item[0], "\t\t",
print "%s\t%s" % (item[1], item[2])
c += 1
ranklist.sort(cmp = cmpcgpa, reverse=True)
c = 1
print "CGPA Wise"
print "-" * 10
for item in ranklist:
print c, ".", item[0], "\t\t",
print "%s\t%s" % (item[1], item[2])
c += 1