This repository has been archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
academicHistory.py
127 lines (90 loc) · 3.76 KB
/
academicHistory.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
from login import login
from bs4 import BeautifulSoup
import threading
#initialising some required variables
history1 = []
history2 = []
grdSumm = []
threadLock = threading.Lock()
threads = []
#overloading thread init and run function
class myThread(threading.Thread):
#overloading the __init__ function
def __init__(self, row, status):
threading.Thread.__init__(self)
self.row = row
self.status = status
#overloading the run function
def run(self):
threadLock.acquire()
scrape(self.row, self.status)
threadLock.release()
#fuction to scrape the row data
def scrape(row, status):
if status == 1:
cells = row.findChildren('td')
cells = cells[1:6]
if cells[2].string.replace("\r\n\t\t","")[0:2] == "ET" or cells[2].string.replace("\r\n\t\t","")[0:2] == "EL" or cells[2].string.replace("\r\n\t\t","")[0:2] == "EP":
history1.append(dict({("course_code" , cells[0].string.replace("\r\n\t\t","")) , ("course_title" , cells[1].string.replace("\r\n\t\t","")) , ("course_type" , cells[2].string.replace("\r\n\t\t","")) , ("credit" , "NA") , ("grade" , "NA")}))
else:
history1.append(dict({("course_title" , cells[1].string.replace("\r\n\t\t","")) , ("course_type" , cells[2].string.replace("\r\n\t\t","")) , ("credit" , cells[3].string) , ("grade" , cells[4].string)}))
elif status == 2:
cells = row.findChildren('td')
history2.append(dict({("credits registered" , cells[0].string.replace("\r\n\t\t","")) , ("credits earned" , cells[1].string.replace("\r\n\t\t","")) , ("cgpa" , cells[2].string.replace("\r\n\t\t","")) , ("rank" , cells[3].string.replace("\r\n\t\t",""))}))
else:
cells = row.findChildren('td')
grdSumm.append(dict({("S grades" , cells[0].string.replace("\r\n\t\t","")) , ("A grades" , cells[1].string.replace("\r\n\t\t","")) , ("B grades" , cells[2].string.replace("\r\n\t\t","")) , ("C grades" , cells[3].string.replace("\r\n\t\t","")) , ("D grades" , cells[4].string.replace("\r\n\t\t","")) , ("E grades" , cells[5].string.replace("\r\n\t\t","")) , ("F grades" , cells[6].string.replace("\r\n\t\t","")) , ("N grades" , cells[7].string.replace("\r\n\t\t",""))}))
#for getting the academic history
def getAcademicHistory(reg_no = "", pwd = ""):
#logging in
br = login(reg_no,pwd)
#checking that are we logged in or not
if br.geturl() == ("https://vtop.vit.ac.in/student/stud_home.asp") or br.geturl() == ("https://vtop.vit.ac.in/student/home.asp"):
print "SUCCESS"
#opening the academic history page
br.open("https://vtop.vit.ac.in/student/student_history.asp")
response = br.open("https://vtop.vit.ac.in/student/student_history.asp")
#getting the soup
soup = BeautifulSoup(response.get_data())
tables = soup.findAll('table')
#getting the required table
myTable = tables[2]
rows = myTable.findChildren(['th','tr'])
rows = rows[1:]
#extracting data
for row in rows:
#creating thread for each row
thrd = myThread(row,1)
#starting the thread
thrd.start()
#appending into thread list
threads.append(thrd)
myTable = tables[3]
rows = myTable.findChildren(['th','tr'])
rows = rows[1:]
#extracting data
for row in rows:
#creating thread for each row
thrd = myThread(row,2)
#starting the thread
thrd.start()
#appending into thread list
threads.append(thrd)
myTable = tables[4]
rows = myTable.findChildren(['th','tr'])
rows = rows[1:]
#extracting data
for row in rows:
#creating thread for each row
thrd = myThread(row,3)
#starting the thread
thrd.start()
#appending into thread list
threads.append(thrd)
#waiting for each thread to complete
for t in threads:
t.join()
return {"status" : "Success" , "history 1" : history1 , "history 2" : history2 , "grade summary" : grdSumm}
else :
print "FAIL"
return {"Status" : "Failure", "Reason" : "Wrong Captcha"}