Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
aditeyabaral committed Apr 30, 2024
1 parent df00203 commit 3a061e5
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 35 deletions.
1 change: 1 addition & 0 deletions pesuacademy/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
AddressDetails,
QualifyingExamination,
)
from .professor import Professor
24 changes: 12 additions & 12 deletions pesuacademy/models/staff.py → pesuacademy/models/professor.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from typing import Optional


class Staff:
class Professor:
def __init__(
self,
name: str,
designation: str,
campus: str,
department: str,
mail: str,
domains: Optional[list] = None,
responsibilities: Optional[list] = None,
education: Optional[list] = None,
experience: Optional[list] = None,
self,
name: str,
designation: str,
campus: str,
department: str,
email: str,
domains: Optional[list] = None,
responsibilities: Optional[list] = None,
education: Optional[list] = None,
experience: Optional[list] = None,
):
self.name = name
self.designation = designation
Expand All @@ -21,7 +21,7 @@ def __init__(
self.department = department
self.campus = campus
self.domains = domains
self.mail = mail
self.email = email
self.responsibilities = responsibilities

def __str__(self):
Expand Down
1 change: 1 addition & 0 deletions pesuacademy/pages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .attendance import AttendancePageHandler
from .courses import CoursesPageHandler
from .profile import ProfilePageHandler
from .faculty import FacultyPageHandler
38 changes: 16 additions & 22 deletions pesuacademy/pages/staff.py → pesuacademy/pages/faculty.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from requests_html import HTMLSession
import requests
from bs4 import BeautifulSoup
from ..models.staff import Staff
import requests_html
from typing import Optional
from pesuacademy.models.professor import Professor


class StaffPageHandler:
class FacultyPageHandler:
@staticmethod
def get_staff_details() -> list:
def get_staff_details() -> list[Professor]:
try:
base_url = "https://staff.pes.edu/atoz/"
session = HTMLSession()
Expand Down Expand Up @@ -127,23 +127,28 @@ def get_details_from_url(url, session):
if responsibilities_div is not None:
p_tags = responsibilities_div.find_all("p")
responsibilities = [p.text for p in p_tags]
Pesu_Staff = Staff(
Pesu_Staff = Professor(
name=name,
designation=designation,
education=professor_education,
experience=professor_experience,
department=department,
campus=campus,
domains=domains,
mail=email,
email=email,
responsibilities=responsibilities,
)
return Pesu_Staff

@staticmethod
def get_staff(department=None, designation=None):
all_staff = StaffPageHandler.get_staff_details()
print(all_staff)
def get_page(
self,
session: requests_html.HTMLSession,
department: Optional[str] = None,
designation: Optional[str] = None,
campus: Optional[str] = None,
) -> list[Professor]:
# TODO: Refactor this to use specific URLs: https://staff.pes.edu/rr/atoz/computer-science/
all_staff = self.get_staff_details()
filtered_staff = all_staff

if department:
Expand All @@ -159,14 +164,3 @@ def get_staff(department=None, designation=None):
]

return filtered_staff


# def main():
# #usage
# cse_staff = StaffPageHandler.get_staff(department="Computer Science")
# for staff_member in cse_staff:
# print(staff_member.name)


# if __name__ == "__main__":
# main()
18 changes: 17 additions & 1 deletion pesuacademy/pesuacademy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pesuacademy import util
from pesuacademy.util.page import PageHandler
from .exceptions import CSRFTokenError, AuthenticationError
from .models import Profile, ClassAndSectionInfo, Course
from .models import Profile, ClassAndSectionInfo, Course, Professor


class PESUAcademy:
Expand Down Expand Up @@ -155,3 +155,19 @@ def attendance(self, semester: Optional[int] = None) -> dict[int, list[Course]]:
raise AuthenticationError("You need to authenticate first.")
attendance_info = self.page_handler.get_attendance(semester)
return attendance_info

def faculty(
self,
department: Optional[str] = None,
designation: Optional[str] = None,
campus: Optional[str] = None,
) -> list[Professor]:
"""
Get the faculty information of the university.
:param department: The department name.
:param designation: The designation of the faculty.
:return: The faculty information.
"""
faculty_info = self.page_handler.get_faculty(department, designation, campus)
return faculty_info
11 changes: 11 additions & 0 deletions pesuacademy/util/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, session: requests_html.HTMLSession):
self.course_page_handler = pages.CoursesPageHandler()
self.attendance_page_handler = pages.AttendancePageHandler()
self.profile_page_handler = pages.ProfilePageHandler()
self.faculty_page_handler = pages.FacultyPageHandler()

def set_semester_id_to_number_mapping(self, csrf_token: str):
try:
Expand Down Expand Up @@ -80,3 +81,13 @@ def get_courses(self, semester: Optional[int] = None):
def get_attendance(self, semester: Optional[int] = None):
semester_ids = self.get_semester_ids_from_semester_number(semester)
return self.attendance_page_handler.get_page(self.__session, semester_ids)

def get_faculty(
self,
department: Optional[str] = None,
designation: Optional[str] = None,
campus: Optional[str] = None,
):
return self.faculty_page_handler.get_page(
self.__session, department, designation, campus
)

0 comments on commit 3a061e5

Please sign in to comment.