From c81b07c277dea02c7b88edbd1469eb40e0995f45 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 25 Aug 2024 13:47:42 +0200 Subject: [PATCH] fix for M2 --- src/info.rs | 9 ++++++++- src/timetable.rs | 16 ++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/info.rs b/src/info.rs index 850399f..42d5476 100644 --- a/src/info.rs +++ b/src/info.rs @@ -34,7 +34,14 @@ pub async fn info( .inner_html(); let re = Regex::new(r"\d{1,2} (septembre|octobre)").unwrap(); - let date = re.captures(&raw_data).unwrap().get(0).unwrap().as_str(); + let date = re.captures(&raw_data).and_then(|caps| caps.get(0)).map_or( + { + let default = "1 septembre"; + println!("Can't find the first week of school, default to : {default}"); + default + }, + |m| m.as_str(), + ); // 1st semester let weeks_s1_1 = 6; // Weeks before break diff --git a/src/timetable.rs b/src/timetable.rs index 6d83214..fb53b48 100644 --- a/src/timetable.rs +++ b/src/timetable.rs @@ -55,8 +55,10 @@ pub async fn timetable( let extra_data = i.select(&sel_span).next().map(|span| span.inner_html().replace("
", "").trim().to_owned() ); + + /* TODO: Instead of searching *_M2, just find any TD_* and TP_* */ let matches = - Regex::new(r"(?PCOURS|TD|TP|COURS_TD) (?P.*) : (?P(lundi|mardi|mercredi|jeudi|vendredi)) (?P.*) \(durée : (?P.*)\)") + Regex::new(r"(?PCOURS|TD|TD_M2|TP|TP_M2|COURS_TD)? (?P.*) : (?P(lundi|mardi|mercredi|jeudi|vendredi)) (?P.*) \(durée : (?P.*)\)") .unwrap() .captures(i.value().attr("title").unwrap()) .unwrap(); @@ -76,13 +78,15 @@ pub async fn timetable( let course = models::Course{ category: match matches .name("type") - .unwrap() - .as_str() { + .map_or("", |m| m.as_str()) { "COURS" => [models::Category::Cours].into(), - "TP" => [models::Category::TP].into(), - "TD" => [models::Category::TD].into(), + "TP" | "TP_M2" => [models::Category::TP].into(), + "TD" | "TD_M2" => [models::Category::TD].into(), "COURS_TD" => [models::Category::Cours, models::Category::TD].into(), - _ => panic!("Unknown type of course") + _ => { + println!("Unknown type of course, falling back to 'COURS': {}", i.value().attr("title").unwrap()); + [models::Category::Cours].into() + }, }, name: matches .name("name")