diff --git a/esprit/absence.py b/esprit/absence.py index 9a333b5..282911a 100644 --- a/esprit/absence.py +++ b/esprit/absence.py @@ -1,4 +1,3 @@ -import requests from bs4 import BeautifulSoup diff --git a/esprit/credit.py b/esprit/credit.py index 04891af..1208e65 100644 --- a/esprit/credit.py +++ b/esprit/credit.py @@ -1,4 +1,3 @@ -import requests from bs4 import BeautifulSoup diff --git a/esprit/esprit.py b/esprit/esprit.py index f1334ab..fc57a0e 100644 --- a/esprit/esprit.py +++ b/esprit/esprit.py @@ -4,6 +4,8 @@ from .absence import Absence from .time_schedule import TimeSchedule from .credit import Credit +from .utils import Utils +# from .exceptions import EspritException #TODO class Esprit: @@ -14,6 +16,7 @@ def __init__(self, driver_path=None, driver=None, debug=False, headless=True): self.absence_scrape = Absence(self.session) self.time_schedule_scrape = TimeSchedule(self.session) self.credit = Credit(self.session) + self.utils = Utils(self.session) def login(self, username, password): cookies = self.auth.login(username, password) @@ -43,3 +46,9 @@ def get_class_week_schedule(self, file_path, class_name, result_path): def get_credits(self): return self.credit.get_credits() + + def get_student_name(self): + return self.utils.get_student_name() + + def get_student_class(self): + return self.utils.get_student_class() diff --git a/esprit/grade.py b/esprit/grade.py index 4eb5df7..5ad776a 100644 --- a/esprit/grade.py +++ b/esprit/grade.py @@ -1,4 +1,3 @@ -import requests from bs4 import BeautifulSoup import pandas as pd import numpy as np diff --git a/esprit/time_schedule.py b/esprit/time_schedule.py index 1429d03..c87f06a 100644 --- a/esprit/time_schedule.py +++ b/esprit/time_schedule.py @@ -1,4 +1,3 @@ -import requests from bs4 import BeautifulSoup from datetime import datetime import re diff --git a/esprit/utils.py b/esprit/utils.py new file mode 100644 index 0000000..045e035 --- /dev/null +++ b/esprit/utils.py @@ -0,0 +1,58 @@ +from bs4 import BeautifulSoup + + +class Utils: + """ + A utility class for interacting with the ESPRIT website. + """ + + def __init__(self, session): + self.url = "https://esprit-tn.com/ESPOnline/Etudiants/Accueil.aspx" + self.session = session + + def get_student_name(self): + """ + Get the name of the student from the ESPRIT website. + + Returns: + The name of the student, or None if the name could not be found. + """ + response = self.session.get(self.url) + soup = BeautifulSoup(response.text, 'html.parser') + + # Check if the

tag with the class "lead" and the text "Vous pouvez consulter dans cet espace :" exists + p_tag = soup.find('p', class_='lead', + text='Vous pouvez consulter dans cet espace :') + if p_tag is None: + print("The page does not contain the expected text.") + return None + + span = soup.find('span', {'id': 'Label2', 'class': 'h4 text-info'}) + if span is not None: + return span.text.strip() + else: + return None + + def get_student_class(self): + """ + Get the class of the student from the ESPRIT website. + + Returns: + The class of the student, or None if the class could not be found. + """ + response = self.session.get(self.url) + soup = BeautifulSoup(response.text, 'html.parser') + + # Check if the

tag with the class "lead" and the text "Vous pouvez consulter dans cet espace :" exists + p_tag = soup.find('p', class_='lead', + text='Vous pouvez consulter dans cet espace :') + if p_tag is None: + print("The page does not contain the expected text.") + return None + + span = soup.find( + 'span', {'id': 'Label3', 'style': 'color:#CC0000;font-weight:bold;'}) + if span is not None: + return span.text.strip() + else: + return None