isenlib 0.9.0__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.
- isenlib-0.9.0/.env.example +3 -0
- isenlib-0.9.0/LICENSE +22 -0
- isenlib-0.9.0/MANIFEST.in +19 -0
- isenlib-0.9.0/PKG-INFO +123 -0
- isenlib-0.9.0/README.md +95 -0
- isenlib-0.9.0/config.example.toml +28 -0
- isenlib-0.9.0/examples/basic_client.py +26 -0
- isenlib-0.9.0/examples/dump_groups.py +25 -0
- isenlib-0.9.0/pyproject.toml +45 -0
- isenlib-0.9.0/setup.cfg +4 -0
- isenlib-0.9.0/src/isenlib/Login.py +70 -0
- isenlib-0.9.0/src/isenlib/__init__.py +25 -0
- isenlib-0.9.0/src/isenlib/cache_store.py +146 -0
- isenlib-0.9.0/src/isenlib/classification.py +223 -0
- isenlib-0.9.0/src/isenlib/cli.py +78 -0
- isenlib-0.9.0/src/isenlib/client.py +803 -0
- isenlib-0.9.0/src/isenlib/config.py +156 -0
- isenlib-0.9.0/src/isenlib/dataClasses.py +171 -0
- isenlib-0.9.0/src/isenlib/default_config.toml +25 -0
- isenlib-0.9.0/src/isenlib/dump.py +127 -0
- isenlib-0.9.0/src/isenlib/http.py +113 -0
- isenlib-0.9.0/src/isenlib/menu.py +161 -0
- isenlib-0.9.0/src/isenlib.egg-info/PKG-INFO +123 -0
- isenlib-0.9.0/src/isenlib.egg-info/SOURCES.txt +26 -0
- isenlib-0.9.0/src/isenlib.egg-info/dependency_links.txt +1 -0
- isenlib-0.9.0/src/isenlib.egg-info/entry_points.txt +2 -0
- isenlib-0.9.0/src/isenlib.egg-info/requires.txt +7 -0
- isenlib-0.9.0/src/isenlib.egg-info/top_level.txt +1 -0
isenlib-0.9.0/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022-2024 CorentinMre
|
|
4
|
+
Copyright (c) 2026 isenlib contributors
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
include LICENSE README.md pyproject.toml
|
|
2
|
+
include config.example.toml .env.example
|
|
3
|
+
graft src/isenlib
|
|
4
|
+
graft examples
|
|
5
|
+
|
|
6
|
+
prune ISENpy
|
|
7
|
+
prune cache
|
|
8
|
+
prune dumps
|
|
9
|
+
prune reports
|
|
10
|
+
prune docs
|
|
11
|
+
prune scripts
|
|
12
|
+
prune .env
|
|
13
|
+
prune .venv
|
|
14
|
+
prune .cursor
|
|
15
|
+
prune build
|
|
16
|
+
prune dist
|
|
17
|
+
|
|
18
|
+
global-exclude *.py[cod] __pycache__ .env.local .env *.pid *.log
|
|
19
|
+
global-exclude .DS_Store
|
isenlib-0.9.0/PKG-INFO
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: isenlib
|
|
3
|
+
Version: 0.9.0
|
|
4
|
+
Summary: Throttled ISEN-Ouest WebAurion client with cached group timetable dumps
|
|
5
|
+
Author: isenlib contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: ISEN,WebAurion,timetable,scraping
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Topic :: Education
|
|
17
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: requests
|
|
22
|
+
Requires-Dist: beautifulsoup4
|
|
23
|
+
Requires-Dist: lxml
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: build; extra == "dev"
|
|
26
|
+
Requires-Dist: twine; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# isenlib
|
|
30
|
+
|
|
31
|
+
Unofficial Python client for **ISEN-Ouest WebAurion**: login, personal data, and **group timetable** discovery/dump with throttling and disk cache.
|
|
32
|
+
|
|
33
|
+
Inspired by [ISENpy](https://github.com/CorentinMre/ISENpy) (MIT). Not affiliated with ISEN or WebAurion.
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install isenlib
|
|
39
|
+
# or from a local checkout:
|
|
40
|
+
pip install .
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Requires Python 3.10+.
|
|
44
|
+
|
|
45
|
+
## Credentials
|
|
46
|
+
|
|
47
|
+
Set environment variables (or a `.env` file in the working directory):
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
export ISEN_USERNAME="your.login"
|
|
51
|
+
export ISEN_PASSWORD="your-password"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Copy `.env.example` → `.env` if you prefer a file. Never commit credentials.
|
|
55
|
+
|
|
56
|
+
## Config (optional)
|
|
57
|
+
|
|
58
|
+
Defaults ship inside the package. Override with `./config.toml`, `~/.config/isenlib/config.toml`, or `ISENLIB_CONFIG=/path/to.toml`.
|
|
59
|
+
|
|
60
|
+
```toml
|
|
61
|
+
[http]
|
|
62
|
+
min_delay_seconds = 0.5
|
|
63
|
+
max_delay_seconds = 1.0
|
|
64
|
+
|
|
65
|
+
[dump]
|
|
66
|
+
cache_dir = "cache"
|
|
67
|
+
output_dir = "dumps"
|
|
68
|
+
default_range_days = 14
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
See `config.example.toml`.
|
|
72
|
+
|
|
73
|
+
Relative `cache` / `dumps` paths are resolved from the **current working directory**.
|
|
74
|
+
|
|
75
|
+
## CLI
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# fill missing groups (uses ./cache)
|
|
79
|
+
isen-dump-timetables
|
|
80
|
+
|
|
81
|
+
# redownload everything
|
|
82
|
+
isen-dump-timetables --force
|
|
83
|
+
|
|
84
|
+
# custom window
|
|
85
|
+
isen-dump-timetables --start 01-12-2026 --end 15-12-2026
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Library
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
import os
|
|
92
|
+
from isenlib import Client, load_config
|
|
93
|
+
|
|
94
|
+
cfg = load_config()
|
|
95
|
+
client = Client(os.environ["ISEN_USERNAME"], os.environ["ISEN_PASSWORD"], config=cfg)
|
|
96
|
+
|
|
97
|
+
print(client.getMyClass())
|
|
98
|
+
print(len(client.planning().data))
|
|
99
|
+
|
|
100
|
+
report = client.getOtherPlanning(
|
|
101
|
+
path=["Plannings des groupes", "Plannings Années 1", "Plannings A1 Caen"],
|
|
102
|
+
group_name="A1C EXP 2026-2027",
|
|
103
|
+
use_cache=True,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
# resume missing groups into ./cache and ./dumps
|
|
107
|
+
client.redownload_timetables(only_missing=True)
|
|
108
|
+
|
|
109
|
+
# overwrite cache
|
|
110
|
+
client.redownload_timetables(force=True)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
More samples in `examples/`.
|
|
114
|
+
|
|
115
|
+
## Notes
|
|
116
|
+
|
|
117
|
+
- Traffic is rate-limited; do not remove delays if you care about account/IP health.
|
|
118
|
+
- School-report downloads only work when WebAurion exposes PDFs for the account.
|
|
119
|
+
- This scrapes a private school portal — use only with credentials you are allowed to use.
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT — see `LICENSE`. Upstream ISENpy © CorentinMre; isenlib additions © contributors.
|
isenlib-0.9.0/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# isenlib
|
|
2
|
+
|
|
3
|
+
Unofficial Python client for **ISEN-Ouest WebAurion**: login, personal data, and **group timetable** discovery/dump with throttling and disk cache.
|
|
4
|
+
|
|
5
|
+
Inspired by [ISENpy](https://github.com/CorentinMre/ISENpy) (MIT). Not affiliated with ISEN or WebAurion.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install isenlib
|
|
11
|
+
# or from a local checkout:
|
|
12
|
+
pip install .
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Requires Python 3.10+.
|
|
16
|
+
|
|
17
|
+
## Credentials
|
|
18
|
+
|
|
19
|
+
Set environment variables (or a `.env` file in the working directory):
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
export ISEN_USERNAME="your.login"
|
|
23
|
+
export ISEN_PASSWORD="your-password"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Copy `.env.example` → `.env` if you prefer a file. Never commit credentials.
|
|
27
|
+
|
|
28
|
+
## Config (optional)
|
|
29
|
+
|
|
30
|
+
Defaults ship inside the package. Override with `./config.toml`, `~/.config/isenlib/config.toml`, or `ISENLIB_CONFIG=/path/to.toml`.
|
|
31
|
+
|
|
32
|
+
```toml
|
|
33
|
+
[http]
|
|
34
|
+
min_delay_seconds = 0.5
|
|
35
|
+
max_delay_seconds = 1.0
|
|
36
|
+
|
|
37
|
+
[dump]
|
|
38
|
+
cache_dir = "cache"
|
|
39
|
+
output_dir = "dumps"
|
|
40
|
+
default_range_days = 14
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
See `config.example.toml`.
|
|
44
|
+
|
|
45
|
+
Relative `cache` / `dumps` paths are resolved from the **current working directory**.
|
|
46
|
+
|
|
47
|
+
## CLI
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# fill missing groups (uses ./cache)
|
|
51
|
+
isen-dump-timetables
|
|
52
|
+
|
|
53
|
+
# redownload everything
|
|
54
|
+
isen-dump-timetables --force
|
|
55
|
+
|
|
56
|
+
# custom window
|
|
57
|
+
isen-dump-timetables --start 01-12-2026 --end 15-12-2026
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Library
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
import os
|
|
64
|
+
from isenlib import Client, load_config
|
|
65
|
+
|
|
66
|
+
cfg = load_config()
|
|
67
|
+
client = Client(os.environ["ISEN_USERNAME"], os.environ["ISEN_PASSWORD"], config=cfg)
|
|
68
|
+
|
|
69
|
+
print(client.getMyClass())
|
|
70
|
+
print(len(client.planning().data))
|
|
71
|
+
|
|
72
|
+
report = client.getOtherPlanning(
|
|
73
|
+
path=["Plannings des groupes", "Plannings Années 1", "Plannings A1 Caen"],
|
|
74
|
+
group_name="A1C EXP 2026-2027",
|
|
75
|
+
use_cache=True,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
# resume missing groups into ./cache and ./dumps
|
|
79
|
+
client.redownload_timetables(only_missing=True)
|
|
80
|
+
|
|
81
|
+
# overwrite cache
|
|
82
|
+
client.redownload_timetables(force=True)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
More samples in `examples/`.
|
|
86
|
+
|
|
87
|
+
## Notes
|
|
88
|
+
|
|
89
|
+
- Traffic is rate-limited; do not remove delays if you care about account/IP health.
|
|
90
|
+
- School-report downloads only work when WebAurion exposes PDFs for the account.
|
|
91
|
+
- This scrapes a private school portal — use only with credentials you are allowed to use.
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
MIT — see `LICENSE`. Upstream ISENpy © CorentinMre; isenlib additions © contributors.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Copy to ./config.toml or ~/.config/isenlib/config.toml
|
|
2
|
+
|
|
3
|
+
[http]
|
|
4
|
+
min_delay_seconds = 0.5
|
|
5
|
+
max_delay_seconds = 1.0
|
|
6
|
+
backoff_base_seconds = 4.0
|
|
7
|
+
max_retries = 3
|
|
8
|
+
timeout_seconds = 30
|
|
9
|
+
|
|
10
|
+
[dns]
|
|
11
|
+
use_public_resolver = true
|
|
12
|
+
resolver = "1.1.1.1"
|
|
13
|
+
|
|
14
|
+
[dump]
|
|
15
|
+
cache_dir = "cache"
|
|
16
|
+
output_dir = "dumps"
|
|
17
|
+
skip_cached = true
|
|
18
|
+
include_old = false
|
|
19
|
+
default_range_days = 14
|
|
20
|
+
# Optional fixed window (dd-mm-yyyy):
|
|
21
|
+
# start_date = "01-12-2026"
|
|
22
|
+
# end_date = "15-12-2026"
|
|
23
|
+
|
|
24
|
+
[school_reports]
|
|
25
|
+
download_dir = "reports"
|
|
26
|
+
|
|
27
|
+
[paths]
|
|
28
|
+
env_file = ".env"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Minimal login + personal planning example."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
from isenlib import Client, load_config
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main() -> int:
|
|
12
|
+
user = os.environ.get("ISEN_USERNAME", "").strip()
|
|
13
|
+
password = os.environ.get("ISEN_PASSWORD", "").strip()
|
|
14
|
+
if not user or not password:
|
|
15
|
+
print("Set ISEN_USERNAME and ISEN_PASSWORD", file=sys.stderr)
|
|
16
|
+
return 2
|
|
17
|
+
|
|
18
|
+
client = Client(user, password, config=load_config())
|
|
19
|
+
print("class:", client.getMyClass())
|
|
20
|
+
planning = client.planning()
|
|
21
|
+
print("events:", len(planning.data))
|
|
22
|
+
return 0
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
if __name__ == "__main__":
|
|
26
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Dump or resume all group timetables into ./cache and ./dumps."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
from isenlib import Client, dump_all_group_plannings, load_config
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main() -> int:
|
|
12
|
+
user = os.environ.get("ISEN_USERNAME", "").strip()
|
|
13
|
+
password = os.environ.get("ISEN_PASSWORD", "").strip()
|
|
14
|
+
if not user or not password:
|
|
15
|
+
print("Set ISEN_USERNAME and ISEN_PASSWORD", file=sys.stderr)
|
|
16
|
+
return 2
|
|
17
|
+
|
|
18
|
+
client = Client(user, password, config=load_config())
|
|
19
|
+
summary = dump_all_group_plannings(client, skip_cached=True)
|
|
20
|
+
print(summary)
|
|
21
|
+
return 0
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
if __name__ == "__main__":
|
|
25
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "isenlib"
|
|
7
|
+
version = "0.9.0"
|
|
8
|
+
description = "Throttled ISEN-Ouest WebAurion client with cached group timetable dumps"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "isenlib contributors" },
|
|
15
|
+
]
|
|
16
|
+
keywords = ["ISEN", "WebAurion", "timetable", "scraping"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 4 - Beta",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: Python :: 3.13",
|
|
26
|
+
"Topic :: Education",
|
|
27
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
28
|
+
]
|
|
29
|
+
dependencies = [
|
|
30
|
+
"requests",
|
|
31
|
+
"beautifulsoup4",
|
|
32
|
+
"lxml",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.optional-dependencies]
|
|
36
|
+
dev = ["build", "twine"]
|
|
37
|
+
|
|
38
|
+
[project.scripts]
|
|
39
|
+
isen-dump-timetables = "isenlib.cli:main_dump_timetables"
|
|
40
|
+
|
|
41
|
+
[tool.setuptools.packages.find]
|
|
42
|
+
where = ["src"]
|
|
43
|
+
|
|
44
|
+
[tool.setuptools.package-data]
|
|
45
|
+
isenlib = ["default_config.toml"]
|
isenlib-0.9.0/setup.cfg
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""WebAurion / Keycloak login."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
from bs4 import BeautifulSoup
|
|
8
|
+
|
|
9
|
+
from .config import AppConfig, load_config
|
|
10
|
+
from .http import ThrottledSession, build_session
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class LoginStudent:
|
|
14
|
+
"""ISEN-Ouest authenticated session."""
|
|
15
|
+
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
username: str,
|
|
19
|
+
password: str,
|
|
20
|
+
config: Optional[AppConfig] = None,
|
|
21
|
+
session: Optional[ThrottledSession] = None,
|
|
22
|
+
) -> None:
|
|
23
|
+
self.config = config or load_config()
|
|
24
|
+
self.session = session or build_session(self.config)
|
|
25
|
+
self.username = username
|
|
26
|
+
self.password = password
|
|
27
|
+
self.page = None
|
|
28
|
+
self.logged_in = self.__login(username, password)
|
|
29
|
+
|
|
30
|
+
def __login(self, username: str, password: str) -> bool:
|
|
31
|
+
req = self.session.get("https://web.isen-ouest.fr/webAurion/?portail=false")
|
|
32
|
+
soup = BeautifulSoup(req.text, "html.parser")
|
|
33
|
+
form = soup.find("form")
|
|
34
|
+
if form is None or not form.get("action"):
|
|
35
|
+
return False
|
|
36
|
+
|
|
37
|
+
payload = {
|
|
38
|
+
"username": username,
|
|
39
|
+
"password": password,
|
|
40
|
+
"credentialId": "",
|
|
41
|
+
}
|
|
42
|
+
for inp in soup.find_all("input"):
|
|
43
|
+
name = inp.get("name")
|
|
44
|
+
if not name or name in payload or inp.get("type") == "submit":
|
|
45
|
+
continue
|
|
46
|
+
payload[name] = inp.get("value") or ""
|
|
47
|
+
|
|
48
|
+
req = self.session.post(form["action"], data=payload)
|
|
49
|
+
self.page = req
|
|
50
|
+
|
|
51
|
+
if req.status_code != 200:
|
|
52
|
+
return False
|
|
53
|
+
|
|
54
|
+
# Failed Keycloak login stays on the auth page.
|
|
55
|
+
title = ""
|
|
56
|
+
soup2 = BeautifulSoup(req.text, "html.parser")
|
|
57
|
+
if soup2.title and soup2.title.text:
|
|
58
|
+
title = soup2.title.text.strip()
|
|
59
|
+
if "Se connecter" in title or "login-actions" in req.url:
|
|
60
|
+
return False
|
|
61
|
+
if "Page d'accueil" in title or "j_idt" in req.text or "webAurion" in req.url:
|
|
62
|
+
return True
|
|
63
|
+
# Accept landing on WebAurion even if title differs.
|
|
64
|
+
return "isen-ouest.fr" in req.url and "auth3" not in req.url
|
|
65
|
+
|
|
66
|
+
def getSession(self):
|
|
67
|
+
return self.session
|
|
68
|
+
|
|
69
|
+
def getPage(self):
|
|
70
|
+
return self.page
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""
|
|
2
|
+
isenlib — throttled WebAurion client for ISEN-Ouest.
|
|
3
|
+
|
|
4
|
+
Based on the unofficial ISENpy project (MIT © CorentinMre), with
|
|
5
|
+
rate-limiting, disk cache, and group timetable dump support.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
__title__ = "isenlib"
|
|
9
|
+
__author__ = "isenlib contributors"
|
|
10
|
+
__license__ = "MIT"
|
|
11
|
+
__copyright__ = "Copyright (c) CorentinMre and isenlib contributors"
|
|
12
|
+
__version__ = "0.9.0"
|
|
13
|
+
|
|
14
|
+
from .client import Client
|
|
15
|
+
from .config import load_config
|
|
16
|
+
from .dump import dump_all_group_plannings
|
|
17
|
+
from . import cache_store
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"Client",
|
|
21
|
+
"load_config",
|
|
22
|
+
"dump_all_group_plannings",
|
|
23
|
+
"cache_store",
|
|
24
|
+
"__version__",
|
|
25
|
+
]
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""Disk cache for group timetables (read / write / force refresh)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import re
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
9
|
+
|
|
10
|
+
from . import classification
|
|
11
|
+
from .config import AppConfig
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def slug(parts: List[str]) -> str:
|
|
15
|
+
text = "__".join(parts)
|
|
16
|
+
text = re.sub(r"[^\w\-]+", "_", text, flags=re.UNICODE)
|
|
17
|
+
return text.strip("_")[:180] or "group"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def range_key(start_date: str, end_date: str) -> str:
|
|
21
|
+
return f"{start_date}_{end_date}"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def cache_file_for(
|
|
25
|
+
config: AppConfig,
|
|
26
|
+
path: List[str],
|
|
27
|
+
group_name: str,
|
|
28
|
+
start_date: str,
|
|
29
|
+
end_date: str,
|
|
30
|
+
) -> Path:
|
|
31
|
+
name = slug(list(path) + [group_name, range_key(start_date, end_date)])
|
|
32
|
+
return config.cache_path() / f"{name}.json"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def dump_file_for(
|
|
36
|
+
config: AppConfig,
|
|
37
|
+
path: List[str],
|
|
38
|
+
group_name: str,
|
|
39
|
+
start_date: str,
|
|
40
|
+
end_date: str,
|
|
41
|
+
) -> Path:
|
|
42
|
+
name = slug(list(path) + [group_name, range_key(start_date, end_date)])
|
|
43
|
+
return config.output_path() / f"{name}.json"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def event_to_dict(event: Any) -> Dict[str, Any]:
|
|
47
|
+
keys = [
|
|
48
|
+
"id",
|
|
49
|
+
"start",
|
|
50
|
+
"end",
|
|
51
|
+
"class_name",
|
|
52
|
+
"type",
|
|
53
|
+
"subject",
|
|
54
|
+
"description",
|
|
55
|
+
"instructors",
|
|
56
|
+
"start_time",
|
|
57
|
+
"end_time",
|
|
58
|
+
"room",
|
|
59
|
+
"class_info",
|
|
60
|
+
]
|
|
61
|
+
return {k: getattr(event, k, None) for k in keys}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def planning_from_payload(payload: Dict[str, Any]) -> classification.PlanningReport:
|
|
65
|
+
events = []
|
|
66
|
+
for raw in payload.get("events") or []:
|
|
67
|
+
events.append(
|
|
68
|
+
classification.Event(
|
|
69
|
+
id=raw.get("id"),
|
|
70
|
+
start=raw.get("start"),
|
|
71
|
+
end=raw.get("end"),
|
|
72
|
+
class_name=raw.get("class_name") or "",
|
|
73
|
+
type=raw.get("type") or "",
|
|
74
|
+
subject=raw.get("subject") or "",
|
|
75
|
+
description=raw.get("description") or "",
|
|
76
|
+
instructors=raw.get("instructors") or "",
|
|
77
|
+
start_time=raw.get("start_time") or "",
|
|
78
|
+
end_time=raw.get("end_time") or "",
|
|
79
|
+
room=raw.get("room") or "",
|
|
80
|
+
class_info=raw.get("class_info") or "",
|
|
81
|
+
)
|
|
82
|
+
)
|
|
83
|
+
return classification.PlanningReport(events=events)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def load_cached(
|
|
87
|
+
config: AppConfig,
|
|
88
|
+
path: List[str],
|
|
89
|
+
group_name: str,
|
|
90
|
+
start_date: str,
|
|
91
|
+
end_date: str,
|
|
92
|
+
) -> Optional[Tuple[Dict[str, Any], classification.PlanningReport]]:
|
|
93
|
+
path_file = cache_file_for(config, path, group_name, start_date, end_date)
|
|
94
|
+
if not path_file.is_file():
|
|
95
|
+
# fall back to dumps/
|
|
96
|
+
path_file = dump_file_for(config, path, group_name, start_date, end_date)
|
|
97
|
+
if not path_file.is_file():
|
|
98
|
+
return None
|
|
99
|
+
payload = json.loads(path_file.read_text(encoding="utf-8"))
|
|
100
|
+
return payload, planning_from_payload(payload)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def save_cached(
|
|
104
|
+
config: AppConfig,
|
|
105
|
+
path: List[str],
|
|
106
|
+
group: Dict[str, str],
|
|
107
|
+
start_date: str,
|
|
108
|
+
end_date: str,
|
|
109
|
+
report: classification.PlanningReport,
|
|
110
|
+
) -> Path:
|
|
111
|
+
config.cache_path().mkdir(parents=True, exist_ok=True)
|
|
112
|
+
config.output_path().mkdir(parents=True, exist_ok=True)
|
|
113
|
+
payload = {
|
|
114
|
+
"path": path,
|
|
115
|
+
"group": group,
|
|
116
|
+
"start_date": start_date,
|
|
117
|
+
"end_date": end_date,
|
|
118
|
+
"events": [event_to_dict(e) for e in report.data],
|
|
119
|
+
}
|
|
120
|
+
cache_path = cache_file_for(config, path, group["name"], start_date, end_date)
|
|
121
|
+
dump_path = dump_file_for(config, path, group["name"], start_date, end_date)
|
|
122
|
+
text = json.dumps(payload, ensure_ascii=False, indent=2)
|
|
123
|
+
cache_path.write_text(text, encoding="utf-8")
|
|
124
|
+
dump_path.write_text(text, encoding="utf-8")
|
|
125
|
+
return cache_path
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def list_cached_group_names(
|
|
129
|
+
config: AppConfig, path: List[str], start_date: str, end_date: str
|
|
130
|
+
) -> set[str]:
|
|
131
|
+
"""Group names already cached for this leaf + date window."""
|
|
132
|
+
prefix = slug(list(path)) + "__"
|
|
133
|
+
key = range_key(start_date, end_date)
|
|
134
|
+
names: set[str] = set()
|
|
135
|
+
for folder in (config.cache_path(), config.output_path()):
|
|
136
|
+
if not folder.is_dir():
|
|
137
|
+
continue
|
|
138
|
+
for f in folder.glob(f"{prefix}*{key}.json"):
|
|
139
|
+
try:
|
|
140
|
+
data = json.loads(f.read_text(encoding="utf-8"))
|
|
141
|
+
name = (data.get("group") or {}).get("name")
|
|
142
|
+
if name:
|
|
143
|
+
names.add(name)
|
|
144
|
+
except Exception:
|
|
145
|
+
continue
|
|
146
|
+
return names
|