-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor refactor and handle no seating bug
- Loading branch information
1 parent
204f130
commit 217ae9e
Showing
9 changed files
with
67 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from .attendance import AttendancePageHandler | ||
from .courses import CoursesPageHandler | ||
from .profile import ProfilePageHandler | ||
from .seating_info import SeatingInfoHandler | ||
from .seating_information import SeatingInformationHandler |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import datetime | ||
|
||
import requests_html | ||
from bs4 import BeautifulSoup | ||
|
||
from pesuacademy.models import SeatingInformation | ||
|
||
|
||
class SeatingInformationHandler: | ||
@staticmethod | ||
def get_seating_information_from_page( | ||
soup: BeautifulSoup, | ||
) -> list[SeatingInformation]: | ||
info_table = soup.find("table", attrs={"id": "seatinginfo"}) | ||
tablebody = info_table.find("tbody") | ||
tablerows = tablebody.find_all("tr") | ||
seating_info = list() | ||
for row in tablerows: | ||
columns = row.find_all("td") | ||
assn_name = columns[0].text.strip() | ||
course_code = columns[1].text.strip() | ||
date = columns[2].text.strip() | ||
time = columns[3].text.strip() | ||
terminal = columns[4].text.strip() | ||
block = columns[5].text.strip() | ||
seating_info.append( | ||
SeatingInformation(assn_name, course_code, date, time, terminal, block) | ||
) | ||
return seating_info | ||
|
||
@staticmethod | ||
def get_page(session: requests_html.HTMLSession) -> list[SeatingInformation]: | ||
try: | ||
profile_url = ( | ||
"https://www.pesuacademy.com/Academy/s/studentProfilePESUAdmin" | ||
) | ||
query = { | ||
"menuId": "655", | ||
"url": "studentProfilePESUAdmin", | ||
"controllerMode": "6404", | ||
"actionType": "5", | ||
"id": "0", | ||
"selectedData": "0", | ||
"_": str(int(datetime.datetime.now().timestamp() * 1000)), | ||
} | ||
response = session.get(profile_url, allow_redirects=False, params=query) | ||
if response.status_code != 200: | ||
raise ConnectionError("Unable to fetch seating info.") | ||
soup = BeautifulSoup(response.text, "lxml") | ||
if ( | ||
(no_seating_tag := soup.find("h5")) is not None | ||
and no_seating_tag.text == "No Test Seating Info is available" | ||
): | ||
return [] | ||
else: | ||
return SeatingInformationHandler.get_seating_information_from_page(soup) | ||
except Exception: | ||
raise ConnectionError("Unable to fetch seating info.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
from pesuacademy.util import profile | ||
from pesuacademy.util import seating_info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.