-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathranklist.py
100 lines (91 loc) · 3.16 KB
/
ranklist.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
from time import sleep
from random import randint
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from pyvirtualdisplay import Display
import csv
rolls = []
result =[]
finalranks = []
branches={"1":"EC","2":"CS","3":"EE","4":"CE","5":"ME","6":"PI","7":"MM"}
"""Generates all the rollnumbers in the required batch and branch"""
def rollgen():
print("--Select Branch--\n1)ECE\n2)CSE\n3)EEE\n4)Civil\n5)Mech\n6)PIE\n7)Meta")
try:
branch = branches[str(input("Enter Your Choice:"))]
except:
print("Maybe You're an idiot or Your branch doesn't exist in NITJSR!")
exit()
batch = str(input("Enter Your Batch:"))
head = batch+"UG"+branch
for i in range(1,91):
rolls.append(head+str(i//100) +(str(i//10)+str(i%10)))
return branch
"""This Function opens the result website and scrapes the name and his/her cgpa and stores it into a list of dicts"""
def resultgen():
semester = str(input("Enter Semester Number(1-8):"))
"""Set the visibility to 1 if you want to watch the scraping process"""
display = Display(visible=1, size=(800, 600))
display.start()
"""To check whether chromedriver exists in your system"""
try:
driver = webdriver.Chrome("/usr/bin/chromedriver")
except:
print("Webdriver path needs to be changed or needs to be installed")
exit()
for roll in rolls:
"""Tries to open the website and exits when the site is down"""
try:
#sleep(2)
driver.get("http://14.139.205.172/web_new/Default.aspx")
except:
print(" The Result Site is Down")
exit()
else:
r_element = driver.find_element_by_id('txtRegno')
#r_element.click()
r_element.send_keys(roll)
r_element.send_keys(Keys.ENTER)
"""This statement throws an exception when the student's result is not published. So when it throws we catch. Ain't?"""
try:
s_element = Select(driver.find_element_by_id('ddlSemester'))
except:
print(roll," Result Not Available")
driver.switch_to_alert().accept()
else:
"""Checks Whether the input semester result is available or not"""
try:
s_element.select_by_value(semester)
except:
print(roll + " Result Not Available")
pass
else:
driver.find_element_by_id('btnimgShowResult').click()
name = driver.find_element_by_id('lblStudentName').text
cgpa = driver.find_element_by_id('lblCPI').text
sgpa = driver.find_element_by_id('lblSPI').text
result.append({"name":name,"cgpa":cgpa,"sgpa":sgpa,"roll":roll})
"""This function Saves the scraped data to a csv file"""
def printresult(branch):
"""Uncomment this to sort by cgpa"""
finalranks=sorted(result,key=lambda k:float(k['cgpa']),reverse=(True))
"""Uncomment this to sort by sgpa"""
#finalranks=sorted(result,key=lambda k:float(k['sgpa']),reverse=(True))
print()
i=1
for i in range(len(finalranks)):
finalranks[i]['Rank']=str(i+1)
keys = finalranks[0].keys()
"""Writing the data to a CSV"""
filename = "result"+branch+".csv"
with open(filename,"w") as writeFile:
writer = csv.DictWriter(writeFile,keys)
writer.writeheader()
writer.writerows(finalranks)
def main():
branch = rollgen()
resultgen()
printresult(branch)
if __name__ == '__main__':
main()