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
/
cal.py
130 lines (88 loc) · 4.06 KB
/
cal.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
129
130
from login import login
from bs4 import BeautifulSoup
import threading
#initialising some required variables
threadLock = threading.Lock()
threads = []
class myThread(threading.Thread):
def __init__(self, br, row, i, calmarks):
threading.Thread.__init__(self)
self.br = br
self.row = row
self.i = i
self.calmarks = calmarks
def run(self):
threadLock.acquire()
scrape(self.br, self.row, self.i, self.calmarks)
threadLock.release()
def scrape(br, row, i, calmarks):
details = []
cells = row.findChildren('td')
br.select_form(nr=i)
i = i+1
r = br.submit()
dsoup = BeautifulSoup(r.get_data())
dtables = dsoup.findChildren('table')
#if table is present
try:
dmyTable = dtables[2]
#if table is absent
except:
br.open("https://vtop.vit.ac.in/student/cal_da.asp?sem=WS")
if cells[2].getText().replace("\r\n\t\t","") not in calmarks.keys():
calmarks[cells[2].getText().replace("\r\n\t\t","")] = {"course_type" : cells[4].getText().replace("\r\n\t\t",""), "faculty" : cells[5].getText().replace("\r\n\t\t",""), "details" : details}
else:
if cells[4].getText().replace("\r\n\t\t","") == "Embedded Lab":
calmarks[cells[2].getText().replace("\r\n\t\t","")+"L"] = {"course_type" : cells[4].getText().replace("\r\n\t\t",""), "faculty" : cells[5].getText().replace("\r\n\t\t",""), "details" : details}
elif cells[4].getText().replace("\r\n\t\t","") == "Embedded Project":
calmarks[cells[2].getText().replace("\r\n\t\t","")+"P"] = {"course_type" : cells[4].getText().replace("\r\n\t\t",""), "faculty" : cells[5].getText().replace("\r\n\t\t",""), "details" : details}
else:
drows = dmyTable.findChildren(['th','tr'])
drows = drows[2:-1]
for drow in drows:
dcells = drow.findAll('td')
details.append({"assignment_title" : dcells[1].getText(), "due_date" : dcells[2].getText(),"max_marks" : dcells[3].getText() ,"assignment_status" : dcells[5].getText() if dcells[5].getText() else "NA", "marks_status" : dcells[7].getText() if dcells[7].getText() else "NA", "marks_score" : dcells[8].getText() if dcells[3].getText() else "NA"})
br.open("https://vtop.vit.ac.in/student/cal_da.asp?sem=WS")
if cells[2].getText().replace("\r\n\t\t","") not in calmarks.keys():
calmarks[cells[2].getText().replace("\r\n\t\t","")] = {"course_type" : cells[4].getText().replace("\r\n\t\t",""), "faculty" : cells[5].getText().replace("\r\n\t\t",""), "details" : details}
else:
if cells[4].getText().replace("\r\n\t\t","") == "Embedded Lab":
calmarks[cells[2].getText().replace("\r\n\t\t","")+"L"] = {"course_type" : cells[4].getText().replace("\r\n\t\t",""), "faculty" : cells[5].getText().replace("\r\n\t\t",""), "details" : details}
elif cells[4].getText().replace("\r\n\t\t","") == "Embedded Project":
calmarks[cells[2].getText().replace("\r\n\t\t","")+"P"] = {"course_type" : cells[4].getText().replace("\r\n\t\t",""), "faculty" : cells[5].getText().replace("\r\n\t\t",""), "details" : details}
def getCalmarks(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 cal marks page
br.open("https://vtop.vit.ac.in/student/cal_da.asp?sem=WS")
response = br.open("https://vtop.vit.ac.in/student/cal_da.asp?sem=WS")
#getting the soup
soup = BeautifulSoup(response.get_data())
#getting the required table
print len(soup.findAll(table))
myTable = soup.findAll('table')[1]
#initialising some required variables
calmarks = {}
rows = myTable.findChildren(['th','tr'])
rows = rows[1:]
calmarks = {}
i = 0
#extracting the table
for row in rows:
#creating thread for each row
thrd = myThread(br, row, i, calmarks)
i= i+1
#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" , "CAL_marks" : calmarks}
else :
print "FAIL"
return {"Status" : "Failure", "Reason" : "Wrong Captcha"}