-
Notifications
You must be signed in to change notification settings - Fork 0
/
attendence_marks.py
113 lines (80 loc) · 3.45 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
from pyquery import PyQuery as pq
import json
import requests
import base64
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):
CourseCode = pq(element).find('td').eq(0).text()
if CourseCode.find("Regular") == -1:
pass
else:
CourseCode = CourseCode[:-8]
AttendanceDetails[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(),
"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[CourseCode] = Marks_each
Marks[CourseCode]["TOTAL"] = MarksTotal
url = "https://academia.srmuniv.ac.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:
headers = {'Origin': 'https://academia.srmuniv.ac.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": "My_Attendance",
"urlParams": {},
"isPageLoad": "true"}
dom = pq(requests.post(url, data=data, headers=headers, cookies=Cookies).text)
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 index, value in AttendanceDetails.items():
if index in Marks:
value["Marks"] = Marks[index]
else:
value["Marks"] = "Not Updated Yet"
AttendanceAndMarks[index] = value
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 in token"}
json_o = json.dumps(json_o)
return json_o