esprit-py 0.3.2__py3-none-any.whl → 0.3.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of esprit-py might be problematic. Click here for more details.

esprit/absence.py CHANGED
@@ -1,4 +1,3 @@
1
- import requests
2
1
  from bs4 import BeautifulSoup
3
2
 
4
3
 
esprit/auth.py CHANGED
@@ -114,6 +114,7 @@ class Auth:
114
114
  Login failed!
115
115
  -------------
116
116
  ''')
117
+ return None
117
118
 
118
119
 
119
120
  # Code for debugging login
esprit/credit.py CHANGED
@@ -1,4 +1,3 @@
1
- import requests
2
1
  from bs4 import BeautifulSoup
3
2
 
4
3
 
esprit/esprit.py CHANGED
@@ -4,6 +4,8 @@ from .grade import Grade
4
4
  from .absence import Absence
5
5
  from .time_schedule import TimeSchedule
6
6
  from .credit import Credit
7
+ from .utils import Utils
8
+ # from .exceptions import EspritException #TODO
7
9
 
8
10
 
9
11
  class Esprit:
@@ -11,10 +13,10 @@ class Esprit:
11
13
  self.session = requests.Session()
12
14
  self.auth = Auth(driver_path, driver, debug, headless)
13
15
  self.grade_scrape = Grade(self.session)
14
- self.grade_scrape = Grade(self.session)
15
16
  self.absence_scrape = Absence(self.session)
16
17
  self.time_schedule_scrape = TimeSchedule(self.session)
17
18
  self.credit = Credit(self.session)
19
+ self.utils = Utils(self.session)
18
20
 
19
21
  def login(self, username, password):
20
22
  cookies = self.auth.login(username, password)
@@ -24,6 +26,9 @@ class Esprit:
24
26
  def get_grades(self):
25
27
  return self.grade_scrape.get_grades()
26
28
 
29
+ def calculate_average(self, grades):
30
+ return self.grade_scrape.calculate_average(grades)
31
+
27
32
  def get_absences(self):
28
33
  return self.absence_scrape.get_absences()
29
34
 
@@ -41,3 +46,9 @@ class Esprit:
41
46
 
42
47
  def get_credits(self):
43
48
  return self.credit.get_credits()
49
+
50
+ def get_student_name(self):
51
+ return self.utils.get_student_name()
52
+
53
+ def get_student_class(self):
54
+ return self.utils.get_student_class()
esprit/grade.py CHANGED
@@ -1,5 +1,6 @@
1
- import requests
2
1
  from bs4 import BeautifulSoup
2
+ import pandas as pd
3
+ import numpy as np
3
4
 
4
5
 
5
6
  class Grade:
@@ -19,6 +20,8 @@ class Grade:
19
20
  -------
20
21
  get_grades():
21
22
  Returns a list of grades for the student.
23
+ calculate_average(grades):
24
+ Calculate the average grade based on the given grades.
22
25
  """
23
26
 
24
27
  def __init__(self, session):
@@ -50,3 +53,50 @@ class Grade:
50
53
  grades = [headers] + [[cell.text.strip() for cell in row.find_all('td')]
51
54
  for row in rows[1:]] # Skip header row
52
55
  return grades
56
+
57
+ def calculate_average(self, grades):
58
+ """
59
+ Calculate the average grade based on the given grades.
60
+
61
+ Parameters
62
+ ----------
63
+ grades (list): A list of lists representing the grades. The first list should contain the column names.
64
+
65
+ Returns
66
+ -------
67
+ float: The calculated average grade.
68
+ """
69
+ # Convert the list of lists to a DataFrame
70
+ df = pd.DataFrame(grades[1:], columns=grades[0])
71
+
72
+ # Replace empty strings with NaN
73
+ df.replace('', np.nan, inplace=True)
74
+
75
+ # Replace comma with dot and convert to float
76
+ for col in ['COEF', 'NOTE_CC', 'NOTE_TP', 'NOTE_EXAM']:
77
+ df[col] = df[col].str.replace(',', '.').astype(float)
78
+
79
+ # Calculate the average based on available grades
80
+
81
+ def calculate_average(row):
82
+ if pd.isna(row['NOTE_TP']):
83
+ if pd.isna(row['NOTE_CC']):
84
+ return row['NOTE_EXAM']
85
+ else:
86
+ return row['NOTE_EXAM'] * 0.6 + row['NOTE_CC'] * 0.4
87
+ elif pd.isna(row['NOTE_CC']):
88
+ return row['NOTE_EXAM'] * 0.8 + row['NOTE_TP'] * 0.2
89
+ else:
90
+ return row['NOTE_EXAM'] * 0.5 + row['NOTE_CC'] * 0.3 + row['NOTE_TP'] * 0.2
91
+
92
+ df['MOYENNE'] = df.apply(calculate_average, axis=1)
93
+
94
+ # Calculate the total average
95
+ total_average = (df['MOYENNE'] * df['COEF']).sum() / df['COEF'].sum()
96
+
97
+ # Append the total average to the DataFrame
98
+ df = df._append({'DESIGNATION': 'Moyenne', 'COEF': df['COEF'].sum(
99
+ ), 'MOYENNE': total_average}, ignore_index=True)
100
+
101
+ print(df)
102
+ return total_average
esprit/time_schedule.py CHANGED
@@ -1,4 +1,3 @@
1
- import requests
2
1
  from bs4 import BeautifulSoup
3
2
  from datetime import datetime
4
3
  import re
esprit/utils.py ADDED
@@ -0,0 +1,57 @@
1
+ from bs4 import BeautifulSoup
2
+
3
+
4
+ class Utils:
5
+ """
6
+ A utility class for interacting with the ESPRIT website.
7
+ """
8
+
9
+ def __init__(self, session):
10
+ self.url = "https://esprit-tn.com/ESPOnline/Etudiants/Accueil.aspx"
11
+ self.session = session
12
+
13
+ def get_student_name(self):
14
+ """
15
+ Get the name of the student from the ESPRIT website.
16
+
17
+ Returns:
18
+ The name of the student, or None if the name could not be found.
19
+ """
20
+ response = self.session.get(self.url)
21
+ soup = BeautifulSoup(response.text, 'html.parser')
22
+
23
+ # Check if the <p> tag with the class "lead" and the string "Vous pouvez consulter dans cet espace :" exists
24
+ p_tag = soup.find('p', class_='lead',
25
+ string='Vous pouvez consulter dans cet espace :')
26
+ if p_tag is None:
27
+ print("The page does not contain the expected text.")
28
+ return None
29
+
30
+ span = soup.find('span', {'id': 'Label2', 'class': 'h4 text-info'})
31
+ if span is not None:
32
+ return span.text.strip()
33
+ else:
34
+ return None
35
+
36
+ def get_student_class(self):
37
+ """
38
+ Get the class of the student from the ESPRIT website.
39
+
40
+ Returns:
41
+ The class of the student, or None if the class could not be found.
42
+ """
43
+ response = self.session.get(self.url)
44
+ soup = BeautifulSoup(response.text, 'html.parser')
45
+
46
+ # Check if the <p> tag with the class "lead" and the string "Vous pouvez consulter dans cet espace :" exists
47
+ p_tag = soup.find('p', class_='lead',
48
+ string='Vous pouvez consulter dans cet espace :')
49
+ if p_tag is None:
50
+ print("The page does not contain the expected text.")
51
+ return None
52
+
53
+ span = soup.find('span', {'id': 'Label3'})
54
+ if span is not None:
55
+ return span.text.strip()
56
+ else:
57
+ return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: esprit-py
3
- Version: 0.3.2
3
+ Version: 0.3.4
4
4
  Summary: A Python library for interacting with data from esprit-tn.com
5
5
  Home-page: https://github.com/TheLime1/esprit.py
6
6
  Author: Lime1 (Aymen Hmani)
@@ -17,6 +17,8 @@ Requires-Dist: requests
17
17
  Requires-Dist: beautifulsoup4
18
18
  Requires-Dist: PyPDF2
19
19
  Requires-Dist: selenium
20
+ Requires-Dist: numpy
21
+ Requires-Dist: pandas
20
22
 
21
23
 
22
24
  # <img src="https://esprit.tn/favicon.ico" width="28px" /> esprit-py
@@ -41,6 +43,8 @@ Requires-Dist: selenium
41
43
 
42
44
  - Get your credits
43
45
 
46
+ - Calculate your total semester average
47
+
44
48
 
45
49
 
46
50
  ## Installation
@@ -55,7 +59,89 @@ pip install esprit-py
55
59
 
56
60
 
57
61
 
58
- ## Example
62
+ download `chromedriver` from [here](https://googlechromelabs.github.io/chrome-for-testing/#stable)
63
+
64
+
65
+
66
+ ## Examples
67
+
68
+
69
+
70
+ get your total avreage:
71
+
72
+
73
+
74
+ ```python
75
+
76
+ from esprit import Esprit
77
+
78
+
79
+
80
+ # Replace with your actual ID and password
81
+
82
+ id = 'ID'
83
+
84
+ password = 'PASSWORD'
85
+
86
+
87
+
88
+ grades = None
89
+
90
+
91
+
92
+ # Keep trying to get grades until it is successful cuz esprit use garabage servers
93
+
94
+ while grades is None:
95
+
96
+ try:
97
+
98
+ # Create an Esprit object
99
+
100
+ esprit = Esprit(
101
+
102
+ driver_path="C:/path/to/chromedriver.exe")
103
+
104
+
105
+
106
+ # Attempt to log in
107
+
108
+ esprit.login(id, password)
109
+
110
+
111
+
112
+ # Get grades
113
+
114
+ grades = esprit.get_grades()
115
+
116
+
117
+
118
+ except Exception as e:
119
+
120
+ print(f"An error occurred: {e}. Retrying...")
121
+
122
+
123
+
124
+ if grades is not None:
125
+
126
+ for grade in grades:
127
+
128
+ print(grade)
129
+
130
+ else:
131
+
132
+ print("Failed to get grades.")
133
+
134
+
135
+
136
+ esprit.calculate_average(grades)
137
+
138
+
139
+
140
+ ```
141
+
142
+
143
+
144
+ get a list of all your absences;
59
145
 
60
146
 
61
147
 
@@ -67,7 +153,9 @@ from esprit import Esprit
67
153
 
68
154
  # Create an Esprit object
69
155
 
70
- esprit = Esprit()
156
+ esprit = Esprit(
157
+
158
+ driver_path="C:/path/to/chromedriver.exe",)
71
159
 
72
160
 
73
161
 
@@ -105,6 +193,10 @@ else:
105
193
 
106
194
  print("Failed to get absences.")
107
195
 
196
+
197
+
108
198
  ```
109
199
 
200
+
201
+
110
202
  More examples can be found in the [examples folder](examples)
@@ -0,0 +1,13 @@
1
+ esprit/__init__.py,sha256=PnahGRQ5xmA26XMFaj9ImLty9OEmYwnBqLanvGXZwwU,28
2
+ esprit/absence.py,sha256=1CE7FCnWUr9omNXkgFH4Q3Vq5FkonjAEOmAOarXoCqU,1649
3
+ esprit/auth.py,sha256=rT46FuRfeM3cCit5ltsLvXxN6rOUY7XEagGcJMXPVlI,4059
4
+ esprit/credit.py,sha256=G4UPVaJEFiucF4dbmwLcCl_OUD419UstPRJ3GeGj5nI,1730
5
+ esprit/esprit.py,sha256=kj46pKuyuJZuCKVxwBehKZVKycKauGYSKpMDmo3n-lw,1961
6
+ esprit/grade.py,sha256=Wt5rjcqHAaG2gQ5DaqaMUMkP7ImMhZhQqoJTxTZkXhk,3504
7
+ esprit/time_schedule.py,sha256=APash3wNe09kdwJDl3B1Du1WH71h6j3TAirVGoWndCc,6473
8
+ esprit/utils.py,sha256=evATWiuwSp80IvKV-jkjLX8kNW6tEYR4Iakr-HQu9gs,2009
9
+ esprit_py-0.3.4.dist-info/LICENSE,sha256=DOcn7qpE6TsUEcakIsDDKm757jx5YlQ8fXDiED21P_w,1089
10
+ esprit_py-0.3.4.dist-info/METADATA,sha256=cYU7wA9DFyaYz8-I8R9vkdM_vIP2xF3e8QXxCdhw0Ao,2863
11
+ esprit_py-0.3.4.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
12
+ esprit_py-0.3.4.dist-info/top_level.txt,sha256=aS9besFTZ4EYTsoBJVf3GaMjQtJLgLaK7WqAxSvGVdQ,7
13
+ esprit_py-0.3.4.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- esprit/__init__.py,sha256=PnahGRQ5xmA26XMFaj9ImLty9OEmYwnBqLanvGXZwwU,28
2
- esprit/absence.py,sha256=qOFyK0QmSaWYrz_2RlDFcCom-m6QZLJAzG1dBj3YkbI,1666
3
- esprit/auth.py,sha256=-jkquqEGZ8I7K61T4QsXHLfDTIwdhbirOrtEmGysbqQ,4034
4
- esprit/credit.py,sha256=iKy_lTR_iLAkpRkP92l2gAUi4Dh6JvLidxGhuM9YJ68,1747
5
- esprit/esprit.py,sha256=5ixvBZESBxlco2AA4apPPfTDUx8wNuc5blC-FZu7dpc,1625
6
- esprit/grade.py,sha256=EAgYvA-490Jj9TeUCIlSQeW4aVu2gcmfujNxDG-91Fw,1648
7
- esprit/time_schedule.py,sha256=sU2gwV9dmIyFhSe0qlxTGg05L7lhLbD0YN0qhMXdNc0,6490
8
- esprit_py-0.3.2.dist-info/LICENSE,sha256=DOcn7qpE6TsUEcakIsDDKm757jx5YlQ8fXDiED21P_w,1089
9
- esprit_py-0.3.2.dist-info/METADATA,sha256=CWa2zN-6vYcdZOhIKdrkHZqd3vLoEGiCW43hnSr-9zA,1722
10
- esprit_py-0.3.2.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
11
- esprit_py-0.3.2.dist-info/top_level.txt,sha256=aS9besFTZ4EYTsoBJVf3GaMjQtJLgLaK7WqAxSvGVdQ,7
12
- esprit_py-0.3.2.dist-info/RECORD,,