-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnitd_results.py
More file actions
80 lines (62 loc) · 2.87 KB
/
Copy pathnitd_results.py
File metadata and controls
80 lines (62 loc) · 2.87 KB
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
import requests
from urllib3.exceptions import InsecureRequestWarning
import json
import pandas as pd
from multiprocessing import Pool
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
DETAILS_PAGE = "https://erp.nitdelhi.ac.in/CampusLynxNITD/CounsellingRequest?sid=2002&refor=StudentSeatingMasterService"
RESULT_PAGE = DETAILS_PAGE.replace("2002", "2005")
SUBJECT_PAGE = DETAILS_PAGE.replace("2002", "2003")
HEADER = {"Content-Type": "application/x-www-form-urlencoded"}
BRANCHES = {
"CSE": list(range(201210001, 201210057)) + [201220039, 201230021, 201230045],
"ECE": sorted((set(range(201220001, 201220056)) | {201230039}) - {201220039}),
"EEE": sorted(set(range(201230001, 201230051)) - {201230021, 201230039, 201230045})
}
jdata = {"sid": "validate", "instituteID": "NITDINSD1506A0000001",
"mname": "ExamSgpaCgpaDetailOfStudent"}
def response(url: str, data: str) -> requests.Response:
while 69:
try:
return requests.post(url, headers=HEADER, data=data, verify=False)
except requests.exceptions.ConnectionError:
continue
def result(r_no: str) -> dict:
stud_id = int(r_no[-2:]) + 56*('300' in r_no) + 106*('200' in r_no)
jdata["studentID"] = 'NITDSTUT2012A0000' + str(stud_id).zfill(3)
stud_data = 'jdata=' + json.dumps(jdata)
r_stud_info = response(DETAILS_PAGE, stud_data)
r_result = response(RESULT_PAGE, stud_data)
if r := r_result.json():
if not r[-1]['sgpa_r']:
return {}
name = r_stud_info.json()[0]['name'].title()
print("Processing", name)
result_info = {'Roll No': int(r_no), 'Name': name}
jdata["stynumber"] = len(r)
sub_data = 'jdata=' + json.dumps(jdata)
r_sub_info = response(SUBJECT_PAGE, sub_data)
for sub in r_sub_info.json():
result_info[sub["subjectdesc"]] = sub['grade']
result_info['CGPA'], result_info["SGPA"] = r[-1]['cgpa_r'], r[-1]['sgpa_r']
return result_info
if __name__ == '__main__':
df, gpa = [], []
with Pool() as pool:
for branch_rolls in BRANCHES.values():
cur_branch = []
for res_info in pool.imap(result, map(str, branch_rolls)):
if not res_info:
continue
gpa_data = list(res_info.items())
gpa_data = dict(gpa_data[:2] + gpa_data[-2:])
gpa.append(gpa_data)
cur_branch.append(res_info)
df.append(pd.DataFrame(cur_branch))
df.insert(0, pd.DataFrame(gpa))
# Remove backlog/dropouts by checking if they do not have the first subject of first roll number
for i in range(4):
df[i] = df[i].dropna(subset=[df[i].columns[2]]).dropna(axis=1)
with pd.ExcelWriter('bob.xlsx') as writer:
for i, sheet in enumerate(['GPA'] + list(BRANCHES)):
df[i].to_excel(writer, sheet, index=None)