isenlib 0.9.0__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.
- isenlib/Login.py +70 -0
- isenlib/__init__.py +25 -0
- isenlib/cache_store.py +146 -0
- isenlib/classification.py +223 -0
- isenlib/cli.py +78 -0
- isenlib/client.py +803 -0
- isenlib/config.py +156 -0
- isenlib/dataClasses.py +171 -0
- isenlib/default_config.toml +25 -0
- isenlib/dump.py +127 -0
- isenlib/http.py +113 -0
- isenlib/menu.py +161 -0
- isenlib-0.9.0.dist-info/METADATA +123 -0
- isenlib-0.9.0.dist-info/RECORD +18 -0
- isenlib-0.9.0.dist-info/WHEEL +5 -0
- isenlib-0.9.0.dist-info/entry_points.txt +2 -0
- isenlib-0.9.0.dist-info/licenses/LICENSE +22 -0
- isenlib-0.9.0.dist-info/top_level.txt +1 -0
isenlib/Login.py
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
|
isenlib/__init__.py
ADDED
|
@@ -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
|
+
]
|
isenlib/cache_store.py
ADDED
|
@@ -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
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# classification.py
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
This file defines classes to represent grades, absences, and planning events, along with their respective reports.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
# Grade
|
|
8
|
+
class Grade:
|
|
9
|
+
def __init__(self, date, code, name, grade, absence, appreciation, instructors):
|
|
10
|
+
# Constructor to initialize Grade object attributes
|
|
11
|
+
self.date = date
|
|
12
|
+
self.code = code
|
|
13
|
+
self.name = name
|
|
14
|
+
self.grade = grade
|
|
15
|
+
self.absence = absence
|
|
16
|
+
self.appreciation = appreciation
|
|
17
|
+
self.instructors = instructors
|
|
18
|
+
|
|
19
|
+
def __repr__(self):
|
|
20
|
+
# Returns a string representation of the Grade object
|
|
21
|
+
return f"Grade(date='{self.date}', code='{self.code}', name='{self.name}', grade='{self.grade}', absence='{self.absence}', appreciation='{self.appreciation}', instructors='{self.instructors}')"
|
|
22
|
+
|
|
23
|
+
def __getitem__(self, key):
|
|
24
|
+
# Allows accessing attributes using dictionary-like syntax
|
|
25
|
+
if key == 'date':
|
|
26
|
+
return self.date
|
|
27
|
+
elif key == 'code':
|
|
28
|
+
return self.code
|
|
29
|
+
elif key == 'name':
|
|
30
|
+
return self.name
|
|
31
|
+
elif key == 'grade':
|
|
32
|
+
return self.grade
|
|
33
|
+
elif key == 'absence':
|
|
34
|
+
return self.absence
|
|
35
|
+
elif key == 'appreciation':
|
|
36
|
+
return self.appreciation
|
|
37
|
+
elif key == 'instructors':
|
|
38
|
+
return self.instructors
|
|
39
|
+
else:
|
|
40
|
+
raise KeyError(f"Invalid key: {key}, valid keys are 'date', 'code', 'name', 'grade', 'absence', 'appreciation', and 'instructors'")
|
|
41
|
+
|
|
42
|
+
class GradeReport:
|
|
43
|
+
def __init__(self, grade_average, grades):
|
|
44
|
+
# Constructor to initialize GradeReport object attributes
|
|
45
|
+
self.average = grade_average
|
|
46
|
+
self.grades = grades
|
|
47
|
+
|
|
48
|
+
def __repr__(self):
|
|
49
|
+
# Returns a string representation of the GradeReport object
|
|
50
|
+
return f"GradeReport(average={self.average}, data={self.grades})"
|
|
51
|
+
|
|
52
|
+
def __getitem__(self, key):
|
|
53
|
+
# Allows accessing attributes using dictionary-like syntax
|
|
54
|
+
if key == 'average':
|
|
55
|
+
return self.average
|
|
56
|
+
elif key == 'data':
|
|
57
|
+
return self.grades
|
|
58
|
+
else:
|
|
59
|
+
raise KeyError(f"Invalid key: {key}, valid keys are 'average' and 'data'")
|
|
60
|
+
|
|
61
|
+
# Absence
|
|
62
|
+
class Absence:
|
|
63
|
+
def __init__(self, date, reason, duration, schedule, course, instructor, subject):
|
|
64
|
+
# Constructor to initialize Absence object attributes
|
|
65
|
+
self.date = date
|
|
66
|
+
self.reason = reason
|
|
67
|
+
self.duration = duration
|
|
68
|
+
self.schedule = schedule
|
|
69
|
+
self.course = course
|
|
70
|
+
self.instructor = instructor
|
|
71
|
+
self.subject = subject
|
|
72
|
+
|
|
73
|
+
def __repr__(self):
|
|
74
|
+
# Returns a string representation of the Absence object
|
|
75
|
+
return f"Absence(date='{self.date}', reason='{self.reason}', duration='{self.duration}', schedule='{self.schedule}', course='{self.course}', instructor='{self.instructor}', subject='{self.subject}')"
|
|
76
|
+
|
|
77
|
+
def __getitem__(self, key):
|
|
78
|
+
# Allows accessing attributes using dictionary-like syntax
|
|
79
|
+
if key == "date":
|
|
80
|
+
return self.date
|
|
81
|
+
elif key == "reason":
|
|
82
|
+
return self.reason
|
|
83
|
+
elif key == "duration":
|
|
84
|
+
return self.duration
|
|
85
|
+
elif key == "schedule":
|
|
86
|
+
return self.schedule
|
|
87
|
+
elif key == "course":
|
|
88
|
+
return self.course
|
|
89
|
+
elif key == "instructor":
|
|
90
|
+
return self.instructor
|
|
91
|
+
elif key == "subject":
|
|
92
|
+
return self.subject
|
|
93
|
+
else:
|
|
94
|
+
raise KeyError(f"Invalid key: {key}, valid keys are 'date', 'reason', 'duration', 'schedule', 'course', 'instructor', and 'subject'")
|
|
95
|
+
|
|
96
|
+
class AbsenceReport:
|
|
97
|
+
def __init__(self, nbAbsences, time, data):
|
|
98
|
+
# Constructor to initialize AbsenceReport object attributes
|
|
99
|
+
self.nbAbsences = nbAbsences
|
|
100
|
+
self.time = time
|
|
101
|
+
self.data = data
|
|
102
|
+
|
|
103
|
+
def __repr__(self):
|
|
104
|
+
# Returns a string representation of the AbsenceReport object
|
|
105
|
+
return f"AbsenceReport(nbAbsences={self.nbAbsences}, time={self.time}, data={self.data})"
|
|
106
|
+
|
|
107
|
+
def __getitem__(self, key):
|
|
108
|
+
# Allows accessing attributes using dictionary-like syntax
|
|
109
|
+
if key == 'nbAbsences':
|
|
110
|
+
return self.nbAbsences
|
|
111
|
+
elif key == 'time':
|
|
112
|
+
return self.time
|
|
113
|
+
elif key == 'data':
|
|
114
|
+
return self.data
|
|
115
|
+
else:
|
|
116
|
+
raise KeyError(f"Invalid key: {key}, valid keys are 'nbAbsences', 'time', and 'data'")
|
|
117
|
+
|
|
118
|
+
# Planning
|
|
119
|
+
class Event:
|
|
120
|
+
def __init__(self, id, start, end, class_name, type, subject, description, instructors, start_time, end_time, room, class_info):
|
|
121
|
+
# Constructor to initialize Event object attributes
|
|
122
|
+
self.id = id
|
|
123
|
+
self.start = start
|
|
124
|
+
self.end = end
|
|
125
|
+
self.class_name = class_name
|
|
126
|
+
self.type = type
|
|
127
|
+
self.subject = subject
|
|
128
|
+
self.description = description
|
|
129
|
+
self.instructors = instructors
|
|
130
|
+
self.start_time = start_time
|
|
131
|
+
self.end_time = end_time
|
|
132
|
+
self.room = room
|
|
133
|
+
self.class_info = class_info
|
|
134
|
+
|
|
135
|
+
def __repr__(self):
|
|
136
|
+
# Returns a string representation of the Event object
|
|
137
|
+
return f"Event(id='{self.id}', start='{self.start}', end='{self.end}', class_name='{self.class_name}', type='{self.type}', subject='{self.subject}', description='{self.description}', instructors='{self.instructors}', start_time='{self.start_time}', end_time='{self.end_time}', room='{self.room}', class_info='{self.class_info}')"
|
|
138
|
+
|
|
139
|
+
def __getitem__(self, key):
|
|
140
|
+
# Allows accessing attributes using dictionary-like syntax
|
|
141
|
+
if key == "id":
|
|
142
|
+
return self.id
|
|
143
|
+
elif key == "start":
|
|
144
|
+
return self.start
|
|
145
|
+
elif key == "end":
|
|
146
|
+
return self.end
|
|
147
|
+
elif key == "class_name":
|
|
148
|
+
return self.class_name
|
|
149
|
+
elif key == "type":
|
|
150
|
+
return self.type
|
|
151
|
+
elif key == "subject":
|
|
152
|
+
return self.subject
|
|
153
|
+
elif key == "description":
|
|
154
|
+
return self.description
|
|
155
|
+
elif key == "instructors":
|
|
156
|
+
return self.instructors
|
|
157
|
+
elif key == "start_time":
|
|
158
|
+
return self.start_time
|
|
159
|
+
elif key == "end_time":
|
|
160
|
+
return self.end_time
|
|
161
|
+
elif key == "room":
|
|
162
|
+
return self.room
|
|
163
|
+
elif key == "class_info":
|
|
164
|
+
return self.class_info
|
|
165
|
+
else:
|
|
166
|
+
raise KeyError(f"Invalid key: {key}, valid keys are 'id', 'start', 'end', 'class_name', 'type', 'subject', 'description', 'instructors', 'start_time', 'end_time', 'room', and 'class_info'")
|
|
167
|
+
|
|
168
|
+
class PlanningReport:
|
|
169
|
+
def __init__(self, events):
|
|
170
|
+
# Constructor to initialize PlanningReport object attributes
|
|
171
|
+
self.data = events
|
|
172
|
+
|
|
173
|
+
def __repr__(self):
|
|
174
|
+
# Returns a string representation of the PlanningReport object
|
|
175
|
+
return f"PlanningReport(data={self.data})"
|
|
176
|
+
|
|
177
|
+
def __getitem__(self, key):
|
|
178
|
+
# Allows accessing attributes using dictionary-like syntax
|
|
179
|
+
if key == 'data':
|
|
180
|
+
return self.data
|
|
181
|
+
else:
|
|
182
|
+
raise KeyError(f"Invalid key: {key}, valid key is 'data'")
|
|
183
|
+
|
|
184
|
+
# School Report
|
|
185
|
+
class SchoolReportData:
|
|
186
|
+
def __init__(self, name, id):
|
|
187
|
+
# Constructor to initialize SchoolReportData object attributes
|
|
188
|
+
self.name = name
|
|
189
|
+
self.id = id
|
|
190
|
+
|
|
191
|
+
def __repr__(self):
|
|
192
|
+
# Returns a string representation of the SchoolReportData object
|
|
193
|
+
return f"SchoolReportData(name='{self.name}', id='{self.id}')"
|
|
194
|
+
|
|
195
|
+
def __getitem__(self, key):
|
|
196
|
+
# Allows accessing attributes using dictionary-like syntax
|
|
197
|
+
if key == 'name':
|
|
198
|
+
return self.name
|
|
199
|
+
elif key == 'id':
|
|
200
|
+
return self.id
|
|
201
|
+
else:
|
|
202
|
+
raise KeyError(f"Invalid key: {key}, valid key is 'name' and 'id'")
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
class SchoolReport:
|
|
207
|
+
def __init__(self, nbReports, data):
|
|
208
|
+
# Constructor to initialize SchoolReport object attributes
|
|
209
|
+
self.nbReports = nbReports
|
|
210
|
+
self.data = data
|
|
211
|
+
|
|
212
|
+
def __repr__(self):
|
|
213
|
+
# Returns a string representation of the SchoolReport object
|
|
214
|
+
return f"SchoolReport(nbReports={self.nbReports}, data={self.data})"
|
|
215
|
+
|
|
216
|
+
def __getitem__(self, key):
|
|
217
|
+
# Allows accessing attributes using dictionary-like syntax
|
|
218
|
+
if key == 'nbReports':
|
|
219
|
+
return self.nbReports
|
|
220
|
+
elif key == 'data':
|
|
221
|
+
return self.data
|
|
222
|
+
else:
|
|
223
|
+
raise KeyError(f"Invalid key: {key}, valid key is 'nbReports' and 'data'")
|
isenlib/cli.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""CLI entrypoints."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from .client import Client
|
|
10
|
+
from .config import load_config
|
|
11
|
+
from .dump import dump_all_group_plannings
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def main_dump_timetables(argv: list[str] | None = None) -> int:
|
|
15
|
+
parser = argparse.ArgumentParser(
|
|
16
|
+
description="Dump all WebAurion group timetables (throttled, cached, resumable)."
|
|
17
|
+
)
|
|
18
|
+
parser.add_argument("--config", default=None, help="Path to config.toml")
|
|
19
|
+
parser.add_argument("--start", default=None, help="Start date dd-mm-yyyy")
|
|
20
|
+
parser.add_argument("--end", default=None, help="End date dd-mm-yyyy")
|
|
21
|
+
parser.add_argument(
|
|
22
|
+
"--force",
|
|
23
|
+
"--redownload",
|
|
24
|
+
action="store_true",
|
|
25
|
+
help="Ignore cache and redownload every group",
|
|
26
|
+
)
|
|
27
|
+
parser.add_argument(
|
|
28
|
+
"--missing-only",
|
|
29
|
+
action="store_true",
|
|
30
|
+
help="Only fetch groups not already cached (default unless --force)",
|
|
31
|
+
)
|
|
32
|
+
parser.add_argument(
|
|
33
|
+
"--include-old",
|
|
34
|
+
action="store_true",
|
|
35
|
+
help="Include Plannings OLD branch",
|
|
36
|
+
)
|
|
37
|
+
args = parser.parse_args(argv)
|
|
38
|
+
|
|
39
|
+
config = load_config(args.config)
|
|
40
|
+
username = os.environ.get("ISEN_USERNAME", "").strip()
|
|
41
|
+
password = os.environ.get("ISEN_PASSWORD", "").strip()
|
|
42
|
+
if not username or not password:
|
|
43
|
+
print(
|
|
44
|
+
"Missing ISEN_USERNAME / ISEN_PASSWORD (set env or create ./.env)",
|
|
45
|
+
file=sys.stderr,
|
|
46
|
+
)
|
|
47
|
+
return 2
|
|
48
|
+
|
|
49
|
+
skip_cached = True
|
|
50
|
+
if args.force:
|
|
51
|
+
skip_cached = False
|
|
52
|
+
elif args.missing_only:
|
|
53
|
+
skip_cached = True
|
|
54
|
+
|
|
55
|
+
try:
|
|
56
|
+
client = Client(username=username, password=password, config=config)
|
|
57
|
+
dump_all_group_plannings(
|
|
58
|
+
client,
|
|
59
|
+
start_date=args.start,
|
|
60
|
+
end_date=args.end,
|
|
61
|
+
skip_cached=skip_cached,
|
|
62
|
+
include_old=True if args.include_old else None,
|
|
63
|
+
force=args.force,
|
|
64
|
+
)
|
|
65
|
+
except KeyboardInterrupt:
|
|
66
|
+
print("[dump] interrupted", flush=True)
|
|
67
|
+
return 130
|
|
68
|
+
except Exception:
|
|
69
|
+
import traceback
|
|
70
|
+
|
|
71
|
+
print("[dump] FATAL:", flush=True)
|
|
72
|
+
traceback.print_exc()
|
|
73
|
+
return 1
|
|
74
|
+
return 0
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
if __name__ == "__main__":
|
|
78
|
+
raise SystemExit(main_dump_timetables())
|