@@ -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