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")