Skip to content

Commit cbef2ea

Browse files
committed
fix: correct errors
1 parent a7d3428 commit cbef2ea

File tree

4 files changed

+66
-68
lines changed

4 files changed

+66
-68
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ RUN mkdir -p /config && chown -R appuser /app /config
1515
COPY requirements.txt .
1616
RUN pip install --no-cache-dir --require-hashes -r requirements.txt
1717

18+
COPY .env .
1819
COPY . .
1920

2021
COPY entrypoint.sh /entrypoint.sh

entrypoint.sh

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
#!/bin/sh
22
# filepath: entrypoint.sh
33

4-
# Récupérer l'UID/GID de appuser dynamiquement
5-
APPUSER_UID=$(id -u appuser 2>/dev/null || echo 1000)
6-
APPUSER_GID=$(id -g appuser 2>/dev/null || echo 1000)
7-
8-
# Changer le propriétaire du dossier monté avec les bonnes permissions
9-
chown -R ${APPUSER_UID}:${APPUSER_GID} /config 2>/dev/null || true
10-
11-
# Exécuter l'application avec l'utilisateur non-root
12-
exec su-exec ${APPUSER_UID}:${APPUSER_GID} "$@"
4+
# On tourne déjà en tant qu'appuser grâce à USER appuser dans le Dockerfile.
5+
# Pas besoin de su-exec : il échoue sur setgroups en environnement non privilégié.
6+
exec "$@"

src/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ def validate_ntfy_url(url):
6767
exit(1)
6868

6969
#? Endpoint de notification NTFY
70+
NTFY_URL_LOCAL_FALLBACK = os.getenv("NTFY_URL_LOCAL_FALLBACK", None)
7071
NTFY_URL = os.getenv("NTFY_URL")
7172
if NTFY_URL:
7273
if not validate_ntfy_url(NTFY_URL):
7374
print("Erreur: L'URL NTFY est invalide. Format attendu: https://domain.com/topic")
7475
exit(1)
7576
print("URL ntfy custom utilisée :", NTFY_URL,"\n")
76-
NTFY_URL_LOCAL_FALLBACK = os.getenv("NTFY_URL_LOCAL_FALLBACK", None)
7777
if NTFY_URL_LOCAL_FALLBACK and not validate_ntfy_url(NTFY_URL_LOCAL_FALLBACK):
7878
print("Erreur: L'URL NTFY_LOCAL_FALLBACK est invalide.")
7979
exit(1)

src/parse.py

Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -74,67 +74,70 @@ def convert_notes_to_json(url_response, json_file):
7474
[fix_encoding_accents(td.get_text(separator=" ", strip=True)) for td in row.find_all("td")]
7575
for row in tbody.find_all("tr")
7676
if "master-1" in row.get("class", [])
77-
]
77+
]
7878

79-
data = [dict(zip(headers, cells)) for cells in rows if any(cells[1:])]
79+
data = [dict(zip(headers, cells)) for cells in rows if any(cells[1:])]
8080

81-
section_map = {
82-
"Projet": "Projet",
83-
"Contrôle Continu": "Contrôle Continu",
84-
"Contrôle Continu": "Contrôle Continu",
85-
"Examen": "Examen"
86-
}
81+
section_map = {
82+
"Projet": "Projet",
83+
"Contrôle Continu": "Contrôle Continu",
84+
"Contrôle Continu": "Contrôle Continu",
85+
"Examen": "Examen"
86+
}
8787

88-
organized = []
89-
i = 0
90-
while i < len(data):
91-
ligne = data[i]
92-
if ligne.get("Coef."):
93-
matiere_nom = ligne[headers[0]]
94-
coef = ligne["Coef."]
95-
sections = {"Projet": [], "Contrôle Continu": [], "Examen": []}
96-
i += 1
97-
while i < len(data) and not data[i].get("Coef."):
98-
sous_ligne = data[i].copy()
99-
titre = sous_ligne[headers[0]].strip()
100-
section = section_map.get(titre)
101-
if section:
102-
# Supprimer la clé inutile
103-
sous_ligne.pop("Coef.", None)
104-
sous_ligne.pop("Rattrapage Re-sit session", None)
105-
sous_ligne.pop("Cours et évaluations Courses and evaluations", None)
106-
# Renommer la pondération au niveau de la section
107-
for key in ["Pondération Weight", "Pond�ration Weight", "PondÁration Weight"]:
108-
if key in sous_ligne:
109-
sous_ligne["pondération - section"] = sous_ligne.pop(key)
110-
if "Notes Grades" in sous_ligne:
111-
sous_ligne["note"] = sous_ligne.pop("Notes Grades")
112-
# Séparation des notes et pondérations multiples
113-
note_val = sous_ligne.pop("note", "")
114-
pond_val = sous_ligne.pop("pondération", "")
115-
notes = []
116-
if note_val and ("(" in note_val and ")" in note_val):
117-
notes = split_notes(note_val)
118-
elif note_val or pond_val:
119-
notes = [{"note": note_val, "pondération": pond_val}]
120-
else:
121-
notes = []
122-
sous_ligne["notes"] = notes
123-
# Remettre la pondération de section si elle existe
124-
if pond_val:
125-
sous_ligne["pondération"] = pond_val
126-
sections[section].append(sous_ligne)
88+
organized = []
89+
i = 0
90+
while i < len(data):
91+
ligne = data[i]
92+
if ligne.get("Coef."):
93+
matiere_nom = ligne[headers[0]]
94+
coef = ligne["Coef."]
95+
sections = {"Projet": [], "Contrôle Continu": [], "Examen": []}
12796
i += 1
128-
if matiere_nom.strip() != "Crédits par indulgence / Leniency credits":
129-
organized.append({
130-
"matiere": matiere_nom,
131-
"coef": coef,
132-
"sections": sections
133-
})
97+
while i < len(data) and not data[i].get("Coef."):
98+
sous_ligne = data[i].copy()
99+
titre = sous_ligne[headers[0]].strip()
100+
section = section_map.get(titre)
101+
if section:
102+
# Supprimer la clé inutile
103+
sous_ligne.pop("Coef.", None)
104+
sous_ligne.pop("Rattrapage Re-sit session", None)
105+
sous_ligne.pop("Cours et évaluations Courses and evaluations", None)
106+
# Renommer la pondération au niveau de la section
107+
for key in ["Pondération Weight", "Pond�ration Weight", "PondÁration Weight"]:
108+
if key in sous_ligne:
109+
sous_ligne["pondération - section"] = sous_ligne.pop(key)
110+
if "Notes Grades" in sous_ligne:
111+
sous_ligne["note"] = sous_ligne.pop("Notes Grades")
112+
# Séparation des notes et pondérations multiples
113+
note_val = sous_ligne.pop("note", "")
114+
pond_val = sous_ligne.pop("pondération", "")
115+
notes = []
116+
if note_val and ("(" in note_val and ")" in note_val):
117+
notes = split_notes(note_val)
118+
elif note_val or pond_val:
119+
notes = [{"note": note_val, "pondération": pond_val}]
120+
else:
121+
notes = []
122+
sous_ligne["notes"] = notes
123+
# Remettre la pondération de section si elle existe
124+
if pond_val:
125+
sous_ligne["pondération"] = pond_val
126+
sections[section].append(sous_ligne)
127+
i += 1
128+
if matiere_nom.strip() != "Crédits par indulgence / Leniency credits":
129+
organized.append({
130+
"matiere": matiere_nom,
131+
"coef": coef,
132+
"sections": sections
133+
})
134+
else:
135+
break
134136
else:
135-
break
136-
else:
137-
i += 1
137+
i += 1
138138

139-
with open(json_file, "w", encoding="utf-8") as f:
140-
json.dump(organized, f, ensure_ascii=False, indent=2)
139+
with open(json_file, "w", encoding="utf-8") as f:
140+
json.dump(organized, f, ensure_ascii=False, indent=2)
141+
except Exception as e:
142+
print(f"Erreur lors du parsing HTML: {e}")
143+
raise

0 commit comments

Comments
 (0)