-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattendence_marks.py
172 lines (123 loc) · 5.22 KB
/
attendence_marks.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
from pyquery import PyQuery as pq
import json
import requests
import base64
import re
AttendanceDetails = []
def getCookieFromToken(token):
try:
token = token.replace('\\n', '\n')
token = base64.decodestring(str.encode(token))
cookie = json.loads(token)
return cookie
except:
return "error"
def get_attendancedata(index, element):
global AttendanceDetails
if index == 0:
AttendanceDetails = []
# print(AttendanceDetails)
CourseCode = pq(element).find('td').eq(0).text()
if CourseCode.find("Regular") == -1:
pass
else:
CourseCode = CourseCode[:-8]
HoursConducted = int(pq(element).find('td').eq(6).text())
HoursAbsent = int(pq(element).find('td').eq(7).text())
HoursPresent = HoursConducted - HoursAbsent
HoursNeeded = 0
SafeToBunk = 0
if HoursConducted != 0:
c = (HoursPresent / HoursConducted) * 100
if c <= 75:
while c <= 75:
c = (HoursPresent / HoursConducted) * 100
HoursConducted += 1
HoursPresent += 1
HoursNeeded += 1
else:
while c > 75:
c = (HoursPresent / HoursConducted) * 100
HoursConducted += 1
SafeToBunk += 1
if (SafeToBunk <= 2):
SafeToBunk = 0
if (SafeToBunk >= 2):
SafeToBunk = SafeToBunk - 2
AttendanceDetails.append({
"CourseCode": CourseCode,
"CourseTitle": pq(element).find('td').eq(1).text(),
"Category": pq(element).find('td').eq(2).text(),
"FacultyName": pq(element).find('td').eq(3).text(),
"Slot": pq(element).find('td').eq(4).text(),
"RoomNo": pq(element).find('td').eq(5).text(),
"HoursConducted": pq(element).find('td').eq(6).text(),
"HoursAbsent": pq(element).find('td').eq(7).text(),
"Attendance": pq(element).find('td').eq(8).text(),
"HoursNeeded": HoursNeeded,
"SafeToBunk": SafeToBunk,
"UniversityPracticalDetails": pq(element).find('td').eq(9).text()})
Marks = []
def get_marks(index, element):
CourseCode = pq(element).find('td').eq(0).text()
Marks_each = {}
MarksTotal = 0
for a in pq(element).find('td').eq(2).find('td'):
testLabel = pq(a).find('strong').text()
testLabelAndMarks = pq(a).text()
testMarks = testLabelAndMarks.replace(testLabel, '')
testMarks = testMarks.replace(" ", "")
Marks_each[testLabel] = testMarks
if (testMarks == "Abs"):
continue
else:
MarksTotal = MarksTotal + float(testMarks)
Marks_each["CourseCode"] = CourseCode;
Marks_each["Total"] = MarksTotal;
if (MarksTotal<25):
Marks_each["Marksneeded"] = 25 - MarksTotal;
else:
Marks_each["Marksneeded"] = "You have good marks";
Marks.append(Marks_each)
url = "https://academia.srmist.edu.in/liveViewHeader.do"
def getAttendenceAndMarks(token):
Cookies = getCookieFromToken(token)
if (Cookies == "error"):
json_o = {"status": "error", "msg": "Error in token"}
json_o = json.dumps(json_o)
return json_o
else:
viewLinkName = "My_Attendance"
headers = {'Origin': 'https://academia.srmist.edu.in',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.89 Safari/537.36'
}
data = {"sharedBy": "srm_university",
"appLinkName": "academia-academic-services",
"viewLinkName": viewLinkName,
"urlParams": {},
"isPageLoad": "true"}
dom = requests.post(url, data=data, headers=headers, cookies=Cookies).text
s1 = '$("#zc-viewcontainer_'+viewLinkName+'").prepend(pageSanitizer.sanitize('
s2 = '});</script>'
a, b = dom.find(s1), dom.find(s2)
dom = pq(dom[a + 56 + len(viewLinkName):b - 5])
dom('table[border="1"]').eq(0).find('tr:nth-child(n + 2)').each(get_attendancedata)
dom('table[align="center"]').eq(2).find('tr:nth-child(n + 2)').each(get_marks)
AttendanceAndMarks = []
for value_att in AttendanceDetails:
for value_marks in Marks:
if value_att["CourseCode"] == value_marks["CourseCode"]:
req_marks = value_marks.copy()
req_marks.pop('CourseCode', None)
value_att["Marks"] = req_marks
else:
continue
AttendanceAndMarks.append(value_att)
if len(AttendanceAndMarks) > 5:
json_o = {"status": "success", "data": AttendanceAndMarks}
json_o = json.dumps(json_o)
return json_o
else:
json_o = {"status": "error", "msg": "Error occured"}
json_o = json.dumps(json_o)
return json_o