-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsemester.py
141 lines (130 loc) · 5.88 KB
/
semester.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
import requests
from bs4 import BeautifulSoup
import json
import string_constants
class Semester(object):
def __init__(self, session, semester, url = ''):
self.session = session
self.semester = semester
if url == '':
current_url = string_constants.url + semester
else:
current_url = url
r = session.get(current_url)
if r.status_code == 200:
html = r.text
html = html.replace('\n', '')
self.soup = BeautifulSoup(html, "lxml")
def _get_current_session_url(self):
soup = self.soup
tag = soup.find('a', {'title':'Latest Enrollment'})
return tag['href']
def get_data(self):
"""docstring for get_data"""
soup = self.soup
all_data = {}
#Getting semester details
details = {}
form = soup.find('form', {'id' : string_constants.form_id})
details_tag_list = form.find_all('input')
details['session'] = details_tag_list[1]['value']
details['credits'] = details_tag_list[2]['value']
details['gpa'] = details_tag_list[3]['value']
subjects = []
i = 1
while True:
i_str = str(i)
if soup.find('span', {'id': string_constants.course_id + i_str}) != None:
subject_details = {}
#Fetching tags with details
code = soup.find('span', {'id' : string_constants.course_code_id + i_str})
course = soup.find('span', {'id' : string_constants.course_id + i_str})
credits = soup.find('span', {'id' : string_constants.course_credit_id + i_str })
grade = soup.find('span', {'id' : string_constants.course_grade_id + i_str})
session = soup.find('span', {'id' : string_constants.course_session_id + i_str})
#Saving them in a dict
subject_details['code'] = str(code.text)
subject_details['course'] = str(course.text)
subject_details['grade'] = str(grade.text)
subject_details['credits'] = str(credits.text)
subject_details['session'] = str(session.text)
subjects.append(subject_details)
i += 1
else:
break
all_data['details'] = details
all_data['sub_details'] = subjects
self.all_data = all_data
return [details, subjects]
def get_attendance(self, url = ''):
"""docstring for get_attendance"""
soup = self.soup
all_data = {}
attendance = []
#Getting attendance details
if url == '':
form = soup.find('form', {'id' : string_constants.form_id})
details_tag_list = form.find_all('input')
current_session = details_tag_list[1]['value']
current_url = string_constants.url_details + current_session
else:
current_url = url
r = self.session.get(current_url)
if r.status_code == 200:
html = r.text
html = html.replace('\n', '')
soup = BeautifulSoup(html, "lxml")
self.soup_detailed = soup
i = 1
while True:
i_str = str(i)
if soup.find('span', {'id' : string_constants.attendance_code_id + i_str})!=None:
attendance_details = {}
subject_name = soup.find('span', {'id' : string_constants.attendance_name_id + i_str})
classes_taken = soup.find('span', {'id' : string_constants.attendance_classes_id + i_str})
classes_absent = soup.find('span', {'id' : string_constants.attendance_absent_id + i_str})
classes_attended = soup.find('span', {'id' : string_constants.attendance_attended_id + i_str})
attendance_percent = soup.find('span', {'id' : string_constants.attendance_percent_id + i_str})
last_updated = soup.find('span', {'id' : string_constants.attendance_last_updated + i_str})
attendance_details['subject_name'] = subject_name.text
attendance_details['classes_taken'] = classes_taken.text
attendance_details['classes_absent'] = classes_absent.text
attendance_details['classes_attended'] = classes_attended.text
attendance_details['attendance_percent'] = attendance_percent.text
attendance_details['last_updated'] = last_updated.text
attendance.append(attendance_details)
i = i + 1
else:
break
all_data['attendance'] = attendance
return all_data
def get_internals(self):
"""docstring for get_internals"""
soup = self.soup_detailed
all_data = {}
internals = []
position = []
for i in '123':
pos = str(soup.text.find('Internal Assessment (IA) - ['+i))
if pos == -1:
continue
position.append(pos + 'ia' + i)
position.sort()
i = 1
while True:
i_str = str(i)
if soup.find('span', {'id' : string_constants.internal_code_id + i_str})!=None:
internal_details = {}
subject_code = soup.find('span', {'id' : string_constants.internal_code_id + i_str})
subject_name = soup.find('span', {'id' : string_constants.internal_subject_name + i_str})
marks = soup.find_all('span', {'id' : string_constants.internal_marks_id + i_str})
internal_details['subject_name'] = str(subject_name.text)
for j in range(len(marks)):
internal_details['sessional'+position[j][-1]] = str(marks[j].text)
internals.append(internal_details)
i = i + 1
else:
break
#self.all_data['internals'] = internals
all_data['internals'] = internals
return all_data