scraping + maj

This commit is contained in:
Valentin Moguérou 2024-09-16 01:31:30 +02:00
parent b76277a6c7
commit 46db162a26
4 changed files with 77 additions and 55 deletions

View File

@ -14,11 +14,10 @@ from discord import Webhook
calendar = { calendar = {
"C": [ "C": [
(date(2023, 10, 21), date(2023, 11, 6)), (date(2024, 10, 19), date(2024, 11, 4)),
(date(2023, 12, 23), date(2024, 1, 8)), (date(2024, 12, 21), date(2025, 1, 6)),
(date(2024, 2, 10), date(2024, 2, 26)), (date(2025, 2, 15), date(2025, 3, 3)),
(date(2024, 4, 6), date(2024, 4, 22)), (date(2025, 4, 12), date(2025, 4, 28)),
(date(2024, 5, 6), date(2024, 5, 11)), # pont un peu gratté
] ]
} }
@ -446,4 +445,4 @@ def test():
colles = term.query_colles_of_student(valentin).order_by("-volume") colles = term.query_colles_of_student(valentin).order_by("-volume")
for c in colles: for c in colles:
print(f"* {c.slot} {c.volume} : {c.base_vol} + {c.swap_plus} - {c.swap_minus}") print(f"* {c.slot} {c.volume} : {c.base_vol} + {c.swap_plus} - {c.swap_minus}")

View File

@ -26,7 +26,7 @@ class PDF(FPDF):
row.cell(etu.last_name.upper()) # Nom row.cell(etu.last_name.upper()) # Nom
row.cell(etu.first_name) # Prénom row.cell(etu.first_name) # Prénom
row.cell(etu.colle_group(term).description) # Groupe row.cell(etu.colle_group(term).description) # Groupe
row.cell(etu.group_of_type(term, "td").description) #row.cell(etu.group_of_type(term, "td").description)
#row.cell("??") # LV1 #row.cell("??") # LV1
#row.cell("??") # LV2 #row.cell("??") # LV2
@ -39,9 +39,9 @@ class PDF(FPDF):
with self.table( with self.table(
align="LEFT", align="LEFT",
width=190, width=270,
line_height=3, line_height=3,
col_widths=(2, 1, 1, 3, 1, *(1,)*len(weeks)), col_widths=(1.2, 1.2, 0.8, 2.4, 1, *(1,)*len(weeks)),
num_heading_rows=2 if heading else 0, num_heading_rows=2 if heading else 0,
first_row_as_headings=heading) as table: first_row_as_headings=heading) as table:
@ -55,7 +55,7 @@ class PDF(FPDF):
header2 = table.row() header2 = table.row()
for lundi in lundis: for lundi in lundis:
header2.cell(lundi.strftime("%d/%m/%y"), align="CENTER") header2.cell(lundi.strftime("%d/%m"), align="CENTER")
for i, c in enumerate(slots): for i, c in enumerate(slots):
@ -99,7 +99,7 @@ def generate(term):
pdf.set_line_width(0.1) pdf.set_line_width(0.1)
base_y = pdf.t_margin + 10 base_y = pdf.t_margin + 10
pdf.set_y(base_y) pdf.set_y(base_y)
pdf.liste_eleves(term) #pdf.liste_eleves(term)
pdf.set_y(base_y) pdf.set_y(base_y)
pdf.table_colloscope(term) pdf.table_colloscope(term)
pdf.y += 3 pdf.y += 3

View File

@ -1,65 +1,88 @@
import csv import csv
from datetime import date, time, timedelta from datetime import date, time, timedelta
from colloscope.models import * from colloscope.models import *
from zoneinfo import ZoneInfo
tz = ZoneInfo("Europe/Paris")
def digest_time(h1):
a = h1.split("h")
return time(hour=int(a[0]), minute=int(a[1]) if a[1] != '' else 0)
def scrape(periode, chemin): def scrape(periode, chemin):
with open(chemin, "r") as file: with open(chemin, "r") as file:
reader = csv.reader(file) reader = csv.reader(file)
headers, *colloscope = list(reader) header1, header2, *colloscope = list(reader)
for l in colloscope: for l in colloscope:
print(l) print(l)
for colleur, matiere, jour, heure, *(rotations) in colloscope: for matiere, infos, *(rotations) in colloscope:
nom_colleur = colleur.lstrip("Mme.").title() if len(infos.split()) == 5:
civilite = "M" if colleur.startswith("M.") else "F" civ1, nom_colleur, j1, h1, salle = infos.split()
if not Colleur.objects.filter(nom=nom_colleur, civilite=civilite).exists():
c = Colleur(civilite=civilite, nom=nom_colleur)
c.save()
else: else:
c = Colleur.objects.get(nom=nom_colleur, civilite=civilite) civ1, nom_colleur, j1, h1, *_ = infos.split()
salle = "ns"
if not Subject.objects.filter(classe=periode.classe, libelle=matiere).exists(): civilite = "M" if civ1 == "M." else "F"
m = Subject(classe=periode.classe, libelle=matiere, code=matiere.upper())
m.save() #print(civilite, nom_colleur, j1, h1, salle, rotations)
else:
m = Subject.objects.get(classe=periode.classe, libelle=matiere)
jours_dict = {"dimanche": 0, "lundi": 1, "mardi": 2, "mercredi": 3, "jeudi": 4, "vendredi": 5, "samedi": 6}
j = jours_dict[jour]
h = time(int(heure[:-1]), 0) colleur_obj, _ = Colleur.objects.get_or_create(
name=nom_colleur,
gender=civilite,
)
jours_dict = {"di": 0, "lu": 1, "ma": 2, "me": 3, "je": 4, "ve": 5, "sa": 6}
subject_obj, _ = Subject.objects.get_or_create(
cls=periode.cls,
description=matiere
)
#print(repr(subject_obj))
time_ = digest_time(h1)
slot_obj, _ = Slot.objects.get_or_create(
term=periode,
day=jours_dict[j1],
time=time_,
duration=timedelta(hours=1),
room=salle,
subject=subject_obj,
colleur=colleur_obj,
type=GroupType.objects.get_or_create(term=periode, description="colle")[0],
capacity=3
)
print("----------------")
print(slot_obj)
if matiere=="InfoTP":
d = timedelta(hours=2)
c2 = 9
else:
d = timedelta(hours=1)
c2 = 3
print(f"--> Traitement de {c=}, {m=}, {j=}, {h=}, {d=}, {c2=}") for i, rot in enumerate(rotations):
if rot=="":
if not Slot.objects.filter(periode=periode, jour=j, heure=h, duree=d, matiere=m, colleur=c, est_colle=True, capacite=c2).exists(): continue
creneau = Slot(periode=periode, jour=j, heure=h, duree=d, salle="nc", matiere=m, colleur=c, est_colle=True, capacite=c2) groupe, _ = Group.objects.get_or_create(
creneau.save() term=periode,type=GroupType.objects.get_or_create(term=periode, description="colle")[0],
else: description=rot
creneau = Slot.objects.get(periode=periode, jour=j, heure=h, duree=d, matiere=m, colleur=c, est_colle=True, capacite=c2) )
for i, r in enumerate(rotations):
sem = headers[4+i].split("/")
sem[2] = "20"+sem[2]
sem.reverse()
s = date.fromisoformat("-".join(sem)) + (j-1) * timedelta(days=1) date_raw = [int(a) for a in header2[i+2].split("/")]
#print(date_raw)
date_ = date(2025 if date_raw[1] < 9 else 2024, date_raw[1], date_raw[0]) + timedelta(days=jours_dict[j1] - 1)
time_processed = datetime(day=date_.day, month=date_.month, year=date_.year, hour=time_.hour, minute=time_.minute, second=time_.second, tzinfo=tz)
#print(time_processed)
#print(f"{i}) {rot}, {header2[i+2]}")
colle_obj, _ = Colle.objects.get_or_create(
slot = slot_obj,
datetime = time_processed
)
colle_obj.groups.add(groupe)
print(colle_obj)
if not Colle.objects.filter(creneau=creneau, date=s):
rot = Colle(creneau=creneau, date=s)
rot.save()
else:
rot = Colle.objects.get(creneau=creneau, date=s)
rot.groupes.add(Group.objects.get(libelle=r))
def main(): def main():
periode = Term.objects.get(id=3) periode = Term.objects.get(id=3)

@ -1 +1 @@
Subproject commit 9e2427d5ae8e7fafef9fe001394e9566e181f217 Subproject commit 811b224d6a8a644dffd6c34cb54acbbd1a0f4db0