schoolapp-api 2.1.0__tar.gz → 2.1.2__tar.gz
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.
- {schoolapp_api-2.1.0/schoolapp_api.egg-info → schoolapp_api-2.1.2}/PKG-INFO +2 -2
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/README.md +50 -50
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/pyproject.toml +2 -1
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/__init__.py +10 -10
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/auth.py +95 -81
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/http_client.py +79 -67
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/school_app_client.py +63 -63
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2/schoolapp_api.egg-info}/PKG-INFO +2 -2
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/LICENSE +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/constants.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/managers/__init__.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/managers/attendance_manager.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/managers/base_manager.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/managers/course_manager.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/managers/grades_manager.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/managers/profile_manager.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/parsers/__init__.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/parsers/absences.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/parsers/annees.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/parsers/filieres.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/parsers/modules.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/parsers/note_elem.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/parsers/note_mod.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/parsers/profile.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/parsers/sanctions.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/parsers/semestres.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/parsers/stats.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/types/__init__.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/types/annee.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/types/base.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/types/element.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/types/module.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api/types/semestre.py +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api.egg-info/SOURCES.txt +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api.egg-info/dependency_links.txt +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api.egg-info/requires.txt +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/schoolapp_api.egg-info/top_level.txt +0 -0
- {schoolapp_api-2.1.0 → schoolapp_api-2.1.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: schoolapp-api
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.2
|
|
4
4
|
Summary: Professional client for interacting with the School App API
|
|
5
5
|
Author: Aferiad Kamal
|
|
6
6
|
License: MIT
|
|
@@ -40,7 +40,7 @@ if client.login("your.email@example.com", "password"):
|
|
|
40
40
|
|
|
41
41
|
# Get your basic info
|
|
42
42
|
profile = client.get_profile()
|
|
43
|
-
print(f"Hello, {profile
|
|
43
|
+
print(f"Hello, {profile['basic_info']['full_name']}!")
|
|
44
44
|
|
|
45
45
|
# Fetch your current semester grades
|
|
46
46
|
grades = client.get_current_elem_note()
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
# SchoolApp API
|
|
2
|
-
|
|
3
|
-
A Python library designed to make interacting with the SchoolApp platform a lot less painful. Instead of wrestling with session cookies and manual HTML scraping, this library gives you a clean, object-oriented way to access your grades, attendance, and profile data.
|
|
4
|
-
|
|
5
|
-
## Why This Exists
|
|
6
|
-
Browsing the SchoolApp web interface manually for updates is slow. If you want to build a custom dashboard, a grade tracker, or a notification bot, you need a reliable way to get that data programmatically. This library takes care of:
|
|
7
|
-
- **Authentication**: Solid session management with automatic CSRF token handling.
|
|
8
|
-
- **Data Cleanup**: Converts messy HTML tables into structured Python objects.
|
|
9
|
-
- **Smart Logic**: Handles nested modules, element-level statistics, and transcript parsing out of the box.
|
|
10
|
-
|
|
11
|
-
## Quick Start
|
|
12
|
-
|
|
13
|
-
### Installation
|
|
14
|
-
You can install the library locally using:
|
|
15
|
-
```bash
|
|
16
|
-
pip install schoolapp-api
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
### Basic Usage
|
|
20
|
-
Getting your data is as simple as this:
|
|
21
|
-
|
|
22
|
-
```python
|
|
23
|
-
from schoolapp_api import SchoolAppClient
|
|
24
|
-
|
|
25
|
-
# Initialize and log in
|
|
26
|
-
client = SchoolAppClient()
|
|
27
|
-
if client.login("your.email@example.com", "password"):
|
|
28
|
-
|
|
29
|
-
# Get your basic info
|
|
30
|
-
profile = client.get_profile()
|
|
31
|
-
print(f"Hello, {profile
|
|
32
|
-
|
|
33
|
-
# Fetch your current semester grades
|
|
34
|
-
grades = client.get_current_elem_note()
|
|
35
|
-
for item in grades:
|
|
36
|
-
print(f"{item.CodeElem}: {item.Moy}")
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Project Layout
|
|
40
|
-
The library is organized into several specific managers, so you always know where to find what you need:
|
|
41
|
-
|
|
42
|
-
- **`grades`**: Handle module marks, element notes, and academic year results.
|
|
43
|
-
- **`attendance`**: Track your absences and see any sanctions.
|
|
44
|
-
- **`profile`**: Access your personal data and administrative files.
|
|
45
|
-
- **`courses`**: Browse the study plan and available modules.
|
|
46
|
-
|
|
47
|
-
For the full details on every class and function, head over to the [**/docs**](./docs/README.md) folder.
|
|
48
|
-
|
|
49
|
-
## Contributions
|
|
50
|
-
Found a bug or have an idea for a new feature? Feel free to open an issue or submit a pull request. Any help making this library better for everyone is appreciated!
|
|
1
|
+
# SchoolApp API
|
|
2
|
+
|
|
3
|
+
A Python library designed to make interacting with the SchoolApp platform a lot less painful. Instead of wrestling with session cookies and manual HTML scraping, this library gives you a clean, object-oriented way to access your grades, attendance, and profile data.
|
|
4
|
+
|
|
5
|
+
## Why This Exists
|
|
6
|
+
Browsing the SchoolApp web interface manually for updates is slow. If you want to build a custom dashboard, a grade tracker, or a notification bot, you need a reliable way to get that data programmatically. This library takes care of:
|
|
7
|
+
- **Authentication**: Solid session management with automatic CSRF token handling.
|
|
8
|
+
- **Data Cleanup**: Converts messy HTML tables into structured Python objects.
|
|
9
|
+
- **Smart Logic**: Handles nested modules, element-level statistics, and transcript parsing out of the box.
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### Installation
|
|
14
|
+
You can install the library locally using:
|
|
15
|
+
```bash
|
|
16
|
+
pip install schoolapp-api
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Basic Usage
|
|
20
|
+
Getting your data is as simple as this:
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from schoolapp_api import SchoolAppClient
|
|
24
|
+
|
|
25
|
+
# Initialize and log in
|
|
26
|
+
client = SchoolAppClient()
|
|
27
|
+
if client.login("your.email@example.com", "password"):
|
|
28
|
+
|
|
29
|
+
# Get your basic info
|
|
30
|
+
profile = client.get_profile()
|
|
31
|
+
print(f"Hello, {profile['basic_info']['full_name']}!")
|
|
32
|
+
|
|
33
|
+
# Fetch your current semester grades
|
|
34
|
+
grades = client.get_current_elem_note()
|
|
35
|
+
for item in grades:
|
|
36
|
+
print(f"{item.CodeElem}: {item.Moy}")
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Project Layout
|
|
40
|
+
The library is organized into several specific managers, so you always know where to find what you need:
|
|
41
|
+
|
|
42
|
+
- **`grades`**: Handle module marks, element notes, and academic year results.
|
|
43
|
+
- **`attendance`**: Track your absences and see any sanctions.
|
|
44
|
+
- **`profile`**: Access your personal data and administrative files.
|
|
45
|
+
- **`courses`**: Browse the study plan and available modules.
|
|
46
|
+
|
|
47
|
+
For the full details on every class and function, head over to the [**/docs**](./docs/README.md) folder.
|
|
48
|
+
|
|
49
|
+
## Contributions
|
|
50
|
+
Found a bug or have an idea for a new feature? Feel free to open an issue or submit a pull request. Any help making this library better for everyone is appreciated!
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "schoolapp-api"
|
|
7
|
-
version = "2.1.
|
|
7
|
+
version = "2.1.2"
|
|
8
8
|
description = "Professional client for interacting with the School App API"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.7"
|
|
@@ -18,3 +18,4 @@ dependencies = [
|
|
|
18
18
|
|
|
19
19
|
[tool.setuptools]
|
|
20
20
|
packages = ["schoolapp_api", "schoolapp_api.managers", "schoolapp_api.parsers", "schoolapp_api.types"]
|
|
21
|
+
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Professional School App API Client
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from .school_app_client import SchoolAppClient
|
|
6
|
-
from .http_client import HTTPClient
|
|
7
|
-
from .auth import AuthManager
|
|
8
|
-
|
|
9
|
-
__version__ = "2.
|
|
10
|
-
__all__ = ["SchoolAppClient", "HTTPClient", "AuthManager"]
|
|
1
|
+
"""
|
|
2
|
+
Professional School App API Client
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from .school_app_client import SchoolAppClient
|
|
6
|
+
from .http_client import HTTPClient
|
|
7
|
+
from .auth import AuthManager
|
|
8
|
+
|
|
9
|
+
__version__ = "2.1.2"
|
|
10
|
+
__all__ = ["SchoolAppClient", "HTTPClient", "AuthManager"]
|
|
@@ -1,81 +1,95 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Authentication and CSRF token management
|
|
3
|
-
"""
|
|
4
|
-
import re
|
|
5
|
-
import logging
|
|
6
|
-
from schoolapp_api.constants import LOGIN_URL
|
|
7
|
-
|
|
8
|
-
logger = logging.getLogger(__name__)
|
|
9
|
-
|
|
10
|
-
class AuthManager:
|
|
11
|
-
"""Handles authentication and CSRF token management"""
|
|
12
|
-
|
|
13
|
-
def __init__(self, http_client, base_url):
|
|
14
|
-
self.http_client = http_client
|
|
15
|
-
self.base_url = base_url
|
|
16
|
-
self.login_url = LOGIN_URL
|
|
17
|
-
self.csrf_token = None
|
|
18
|
-
self.logged_in = False
|
|
19
|
-
|
|
20
|
-
@staticmethod
|
|
21
|
-
def extract_csrf_token(html_content):
|
|
22
|
-
"""Extract CSRF token from HTML content"""
|
|
23
|
-
match = re.search(r'name="_csrf"\s+value="([^"]+)"', html_content)
|
|
24
|
-
return match.group(1) if match else None
|
|
25
|
-
|
|
26
|
-
def update_csrf_token(self, html_content):
|
|
27
|
-
"""Update CSRF token from HTML content"""
|
|
28
|
-
new_csrf = self.extract_csrf_token(html_content)
|
|
29
|
-
if new_csrf:
|
|
30
|
-
self.csrf_token = new_csrf
|
|
31
|
-
return True
|
|
32
|
-
return False
|
|
33
|
-
|
|
34
|
-
def login(self, email, password):
|
|
35
|
-
"""Login and maintain session"""
|
|
36
|
-
if self.logged_in:
|
|
37
|
-
logger.info("Already logged in!")
|
|
38
|
-
return True
|
|
39
|
-
|
|
40
|
-
logger.info("Fetching login page...")
|
|
41
|
-
code, url, content = self.http_client.get(self.login_url)
|
|
42
|
-
|
|
43
|
-
if not content or not self.update_csrf_token(content):
|
|
44
|
-
logger.error("Failed to fetch login page or retrieve CSRF token.")
|
|
45
|
-
return False
|
|
46
|
-
|
|
47
|
-
logger.info(f"Got CSRF token, logging in...")
|
|
48
|
-
login_data = {
|
|
49
|
-
'_csrf': self.csrf_token,
|
|
50
|
-
'email': email,
|
|
51
|
-
'password': password
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
code, response_url, content = self.http_client.post(
|
|
55
|
-
self.login_url,
|
|
56
|
-
login_data,
|
|
57
|
-
referer=self.login_url
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
if response_url and ("/login" in response_url and "error" in response_url):
|
|
61
|
-
logger.error("Login failed! Invalid credentials.")
|
|
62
|
-
return False
|
|
63
|
-
|
|
64
|
-
logger.info("Login successful!")
|
|
65
|
-
self.logged_in = True
|
|
66
|
-
return True
|
|
67
|
-
|
|
68
|
-
def is_logged_in(self):
|
|
69
|
-
"""Check if currently logged in"""
|
|
70
|
-
return self.logged_in
|
|
71
|
-
|
|
72
|
-
def
|
|
73
|
-
"""
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return False
|
|
1
|
+
"""
|
|
2
|
+
Authentication and CSRF token management
|
|
3
|
+
"""
|
|
4
|
+
import re
|
|
5
|
+
import logging
|
|
6
|
+
from schoolapp_api.constants import LOGIN_URL
|
|
7
|
+
|
|
8
|
+
logger = logging.getLogger(__name__)
|
|
9
|
+
|
|
10
|
+
class AuthManager:
|
|
11
|
+
"""Handles authentication and CSRF token management"""
|
|
12
|
+
|
|
13
|
+
def __init__(self, http_client, base_url):
|
|
14
|
+
self.http_client = http_client
|
|
15
|
+
self.base_url = base_url
|
|
16
|
+
self.login_url = LOGIN_URL
|
|
17
|
+
self.csrf_token = None
|
|
18
|
+
self.logged_in = False
|
|
19
|
+
|
|
20
|
+
@staticmethod
|
|
21
|
+
def extract_csrf_token(html_content):
|
|
22
|
+
"""Extract CSRF token from HTML content"""
|
|
23
|
+
match = re.search(r'name=["\']_csrf["\']\s+value=["\']([^"\']+)["\']', html_content)
|
|
24
|
+
return match.group(1) if match else None
|
|
25
|
+
|
|
26
|
+
def update_csrf_token(self, html_content):
|
|
27
|
+
"""Update CSRF token from HTML content"""
|
|
28
|
+
new_csrf = self.extract_csrf_token(html_content)
|
|
29
|
+
if new_csrf:
|
|
30
|
+
self.csrf_token = new_csrf
|
|
31
|
+
return True
|
|
32
|
+
return False
|
|
33
|
+
|
|
34
|
+
def login(self, email, password):
|
|
35
|
+
"""Login and maintain session"""
|
|
36
|
+
if self.logged_in:
|
|
37
|
+
logger.info("Already logged in!")
|
|
38
|
+
return True
|
|
39
|
+
|
|
40
|
+
logger.info("Fetching login page...")
|
|
41
|
+
code, url, content = self.http_client.get(self.login_url)
|
|
42
|
+
|
|
43
|
+
if not content or not self.update_csrf_token(content):
|
|
44
|
+
logger.error("Failed to fetch login page or retrieve CSRF token.")
|
|
45
|
+
return False
|
|
46
|
+
|
|
47
|
+
logger.info(f"Got CSRF token, logging in...")
|
|
48
|
+
login_data = {
|
|
49
|
+
'_csrf': self.csrf_token,
|
|
50
|
+
'email': email,
|
|
51
|
+
'password': password
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
code, response_url, content = self.http_client.post(
|
|
55
|
+
self.login_url,
|
|
56
|
+
login_data,
|
|
57
|
+
referer=self.login_url
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
if response_url and ("/login" in response_url and "error" in response_url):
|
|
61
|
+
logger.error("Login failed! Invalid credentials.")
|
|
62
|
+
return False
|
|
63
|
+
|
|
64
|
+
logger.info("Login successful!")
|
|
65
|
+
self.logged_in = True
|
|
66
|
+
return True
|
|
67
|
+
|
|
68
|
+
def is_logged_in(self):
|
|
69
|
+
"""Check if currently logged in"""
|
|
70
|
+
return self.logged_in
|
|
71
|
+
|
|
72
|
+
def check_session(self):
|
|
73
|
+
"""
|
|
74
|
+
Confirm whether the session is still valid.
|
|
75
|
+
"""
|
|
76
|
+
code, url, content = self.http_client.get(self.login_url)
|
|
77
|
+
|
|
78
|
+
# If server redirects us back to login, session is dead
|
|
79
|
+
if url and "/login" in url:
|
|
80
|
+
self.logged_in = False
|
|
81
|
+
return False
|
|
82
|
+
|
|
83
|
+
self.logged_in = True
|
|
84
|
+
return True
|
|
85
|
+
|
|
86
|
+
def refresh_csrf_from_url(self, url):
|
|
87
|
+
"""Fetch a fresh CSRF token from a specific page"""
|
|
88
|
+
try:
|
|
89
|
+
code, response_url, content = self.http_client.get(url)
|
|
90
|
+
if content and self.update_csrf_token(content):
|
|
91
|
+
return True
|
|
92
|
+
return False
|
|
93
|
+
except Exception as e:
|
|
94
|
+
logger.warning(f"CSRF refresh warning: {e}")
|
|
95
|
+
return False
|
|
@@ -1,67 +1,79 @@
|
|
|
1
|
-
"""
|
|
2
|
-
HTTP Client with session and cookie management
|
|
3
|
-
"""
|
|
4
|
-
import urllib.request
|
|
5
|
-
import urllib.parse
|
|
6
|
-
import urllib.error
|
|
7
|
-
import http.cookiejar
|
|
8
|
-
import logging
|
|
9
|
-
|
|
10
|
-
from schoolapp_api.constants import DEFAULT_HEADERS
|
|
11
|
-
|
|
12
|
-
logger = logging.getLogger(__name__)
|
|
13
|
-
|
|
14
|
-
class
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def
|
|
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
|
-
|
|
1
|
+
"""
|
|
2
|
+
HTTP Client with session and cookie management
|
|
3
|
+
"""
|
|
4
|
+
import urllib.request
|
|
5
|
+
import urllib.parse
|
|
6
|
+
import urllib.error
|
|
7
|
+
import http.cookiejar
|
|
8
|
+
import logging
|
|
9
|
+
|
|
10
|
+
from schoolapp_api.constants import DEFAULT_HEADERS
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
class NoRedirectHandler(urllib.request.HTTPRedirectHandler):
|
|
15
|
+
def redirect_request(self, req, fp, code, msg, headers, newurl):
|
|
16
|
+
raise urllib.error.HTTPError(
|
|
17
|
+
req.full_url, code, msg, headers, fp
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class HTTPClient:
|
|
22
|
+
"""Base HTTP client for making authenticated requests"""
|
|
23
|
+
|
|
24
|
+
def __init__(self, base_url):
|
|
25
|
+
self.base_url = base_url
|
|
26
|
+
self.cookie_jar = http.cookiejar.CookieJar()
|
|
27
|
+
opener = urllib.request.build_opener(
|
|
28
|
+
urllib.request.HTTPCookieProcessor(self.cookie_jar),
|
|
29
|
+
NoRedirectHandler()
|
|
30
|
+
)
|
|
31
|
+
urllib.request.install_opener(opener)
|
|
32
|
+
# opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(self.cookie_jar))
|
|
33
|
+
# urllib.request.install_opener(opener)
|
|
34
|
+
self.headers = DEFAULT_HEADERS.copy()
|
|
35
|
+
|
|
36
|
+
def get(self, url, params=None):
|
|
37
|
+
"""Perform GET request"""
|
|
38
|
+
try:
|
|
39
|
+
if params:
|
|
40
|
+
query_string = urllib.parse.urlencode(params, doseq=True)
|
|
41
|
+
separator = "&" if "?" in url else "?"
|
|
42
|
+
url = f"{url}{separator}{query_string}"
|
|
43
|
+
|
|
44
|
+
req = urllib.request.Request(url, headers=self.headers, method="GET")
|
|
45
|
+
|
|
46
|
+
with urllib.request.urlopen(req) as response:
|
|
47
|
+
code = response.getcode()
|
|
48
|
+
response_url = response.geturl()
|
|
49
|
+
content = response.read().decode("utf-8")
|
|
50
|
+
return code, response_url, content
|
|
51
|
+
|
|
52
|
+
except urllib.error.HTTPError as e:
|
|
53
|
+
logger.error(f"HTTP Error {e.code}: {e.reason}")
|
|
54
|
+
return e.code, None, None
|
|
55
|
+
except Exception as e:
|
|
56
|
+
logger.error(f"GET Error: {e}")
|
|
57
|
+
return None, None, None
|
|
58
|
+
|
|
59
|
+
def post(self, url, data, referer=None):
|
|
60
|
+
"""Perform POST request"""
|
|
61
|
+
try:
|
|
62
|
+
encoded_data = urllib.parse.urlencode(data).encode('utf-8')
|
|
63
|
+
req = urllib.request.Request(url, data=encoded_data, headers=self.headers)
|
|
64
|
+
req.add_header('Content-Type', 'application/x-www-form-urlencoded')
|
|
65
|
+
req.add_header('Origin', self.base_url)
|
|
66
|
+
if referer:
|
|
67
|
+
req.add_header('Referer', referer)
|
|
68
|
+
|
|
69
|
+
with urllib.request.urlopen(req) as response:
|
|
70
|
+
code = response.getcode()
|
|
71
|
+
response_url = response.geturl()
|
|
72
|
+
content = response.read().decode('utf-8')
|
|
73
|
+
return code, response_url, content
|
|
74
|
+
except urllib.error.HTTPError as e:
|
|
75
|
+
logger.error(f"HTTP Error {e.code}: {e.reason}")
|
|
76
|
+
return e.code, None, None
|
|
77
|
+
except Exception as e:
|
|
78
|
+
logger.error(f"POST Error: {e}")
|
|
79
|
+
return None, None, None
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Professional client for interacting with the School App
|
|
3
|
-
"""
|
|
4
|
-
from schoolapp_api.http_client import HTTPClient
|
|
5
|
-
from schoolapp_api.auth import AuthManager
|
|
6
|
-
from schoolapp_api.constants import BASE_URL
|
|
7
|
-
from schoolapp_api.managers import (
|
|
8
|
-
GradesManager, AttendanceManager, ProfileManager, CourseManager
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
class SchoolAppClient:
|
|
12
|
-
"""Main client for the School App API"""
|
|
13
|
-
|
|
14
|
-
def __init__(self, base_url=BASE_URL):
|
|
15
|
-
self.base_url = base_url
|
|
16
|
-
self.http_client = HTTPClient(self.base_url)
|
|
17
|
-
self.auth = AuthManager(self.http_client, self.base_url)
|
|
18
|
-
|
|
19
|
-
# Initialize Managers
|
|
20
|
-
self.grades = GradesManager(self)
|
|
21
|
-
self.attendance = AttendanceManager(self)
|
|
22
|
-
self.profile = ProfileManager(self)
|
|
23
|
-
self.courses = CourseManager(self)
|
|
24
|
-
|
|
25
|
-
def login(self, email, password):
|
|
26
|
-
"""Authenticate user"""
|
|
27
|
-
return self.auth.login(email, password)
|
|
28
|
-
|
|
29
|
-
# ---------------------------------------------------------
|
|
30
|
-
# Legacy / Convenience methods for backward compatibility
|
|
31
|
-
# ---------------------------------------------------------
|
|
32
|
-
|
|
33
|
-
def get_profile(self):
|
|
34
|
-
return self.profile.get_profile()
|
|
35
|
-
|
|
36
|
-
def get_filieres(self):
|
|
37
|
-
return self.profile.get_filieres()
|
|
38
|
-
|
|
39
|
-
def get_absences(self):
|
|
40
|
-
return self.attendance.get_absences()
|
|
41
|
-
|
|
42
|
-
def get_sanctions(self):
|
|
43
|
-
return self.attendance.get_sanctions()
|
|
44
|
-
|
|
45
|
-
def get_elem_note(self):
|
|
46
|
-
return self.grades.get_element_notes()
|
|
47
|
-
|
|
48
|
-
def get_current_elem_note(self):
|
|
49
|
-
return self.grades.get_element_notes(current=True)
|
|
50
|
-
|
|
51
|
-
def get_mod_note(self):
|
|
52
|
-
return self.grades.get_module_notes()
|
|
53
|
-
|
|
54
|
-
def get_current_mod_note(self):
|
|
55
|
-
return self.grades.get_module_notes(current=True)
|
|
56
|
-
|
|
57
|
-
def get_annee(self):
|
|
58
|
-
return self.grades.get_years()
|
|
59
|
-
|
|
60
|
-
def get_semestre(self):
|
|
61
|
-
return self.grades.get_semesters()
|
|
62
|
-
|
|
63
|
-
def get_modules(self, niveau, filiere, semestre, refresh_csrf=False):
|
|
1
|
+
"""
|
|
2
|
+
Professional client for interacting with the School App
|
|
3
|
+
"""
|
|
4
|
+
from schoolapp_api.http_client import HTTPClient
|
|
5
|
+
from schoolapp_api.auth import AuthManager
|
|
6
|
+
from schoolapp_api.constants import BASE_URL
|
|
7
|
+
from schoolapp_api.managers import (
|
|
8
|
+
GradesManager, AttendanceManager, ProfileManager, CourseManager
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
class SchoolAppClient:
|
|
12
|
+
"""Main client for the School App API"""
|
|
13
|
+
|
|
14
|
+
def __init__(self, base_url=BASE_URL):
|
|
15
|
+
self.base_url = base_url
|
|
16
|
+
self.http_client = HTTPClient(self.base_url)
|
|
17
|
+
self.auth = AuthManager(self.http_client, self.base_url)
|
|
18
|
+
|
|
19
|
+
# Initialize Managers
|
|
20
|
+
self.grades = GradesManager(self)
|
|
21
|
+
self.attendance = AttendanceManager(self)
|
|
22
|
+
self.profile = ProfileManager(self)
|
|
23
|
+
self.courses = CourseManager(self)
|
|
24
|
+
|
|
25
|
+
def login(self, email, password):
|
|
26
|
+
"""Authenticate user"""
|
|
27
|
+
return self.auth.login(email, password)
|
|
28
|
+
|
|
29
|
+
# ---------------------------------------------------------
|
|
30
|
+
# Legacy / Convenience methods for backward compatibility
|
|
31
|
+
# ---------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
def get_profile(self):
|
|
34
|
+
return self.profile.get_profile()
|
|
35
|
+
|
|
36
|
+
def get_filieres(self):
|
|
37
|
+
return self.profile.get_filieres()
|
|
38
|
+
|
|
39
|
+
def get_absences(self):
|
|
40
|
+
return self.attendance.get_absences()
|
|
41
|
+
|
|
42
|
+
def get_sanctions(self):
|
|
43
|
+
return self.attendance.get_sanctions()
|
|
44
|
+
|
|
45
|
+
def get_elem_note(self):
|
|
46
|
+
return self.grades.get_element_notes()
|
|
47
|
+
|
|
48
|
+
def get_current_elem_note(self):
|
|
49
|
+
return self.grades.get_element_notes(current=True)
|
|
50
|
+
|
|
51
|
+
def get_mod_note(self):
|
|
52
|
+
return self.grades.get_module_notes()
|
|
53
|
+
|
|
54
|
+
def get_current_mod_note(self):
|
|
55
|
+
return self.grades.get_module_notes(current=True)
|
|
56
|
+
|
|
57
|
+
def get_annee(self):
|
|
58
|
+
return self.grades.get_years()
|
|
59
|
+
|
|
60
|
+
def get_semestre(self):
|
|
61
|
+
return self.grades.get_semesters()
|
|
62
|
+
|
|
63
|
+
def get_modules(self, niveau, filiere, semestre, refresh_csrf=False):
|
|
64
64
|
return self.courses.get_modules(niveau, filiere, semestre, refresh_csrf)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: schoolapp-api
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.2
|
|
4
4
|
Summary: Professional client for interacting with the School App API
|
|
5
5
|
Author: Aferiad Kamal
|
|
6
6
|
License: MIT
|
|
@@ -40,7 +40,7 @@ if client.login("your.email@example.com", "password"):
|
|
|
40
40
|
|
|
41
41
|
# Get your basic info
|
|
42
42
|
profile = client.get_profile()
|
|
43
|
-
print(f"Hello, {profile
|
|
43
|
+
print(f"Hello, {profile['basic_info']['full_name']}!")
|
|
44
44
|
|
|
45
45
|
# Fetch your current semester grades
|
|
46
46
|
grades = client.get_current_elem_note()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|