fix for M2

This commit is contained in:
Mylloon 2024-08-25 13:47:42 +02:00
parent 181ebf53f4
commit c81b07c277
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 18 additions and 7 deletions

View file

@ -34,7 +34,14 @@ pub async fn info(
.inner_html(); .inner_html();
let re = Regex::new(r"\d{1,2} (septembre|octobre)").unwrap(); 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 // 1st semester
let weeks_s1_1 = 6; // Weeks before break let weeks_s1_1 = 6; // Weeks before break

View file

@ -55,8 +55,10 @@ pub async fn timetable(
let extra_data = i.select(&sel_span).next().map(|span| let extra_data = i.select(&sel_span).next().map(|span|
span.inner_html().replace("<br>", "").trim().to_owned() span.inner_html().replace("<br>", "").trim().to_owned()
); );
/* TODO: Instead of searching *_M2, just find any TD_* and TP_* */
let matches = let matches =
Regex::new(r"(?P<type>COURS|TD|TP|COURS_TD) (?P<name>.*) : (?P<day>(lundi|mardi|mercredi|jeudi|vendredi)) (?P<startime>.*) \(durée : (?P<duration>.*)\)") Regex::new(r"(?P<type>COURS|TD|TD_M2|TP|TP_M2|COURS_TD)? (?P<name>.*) : (?P<day>(lundi|mardi|mercredi|jeudi|vendredi)) (?P<startime>.*) \(durée : (?P<duration>.*)\)")
.unwrap() .unwrap()
.captures(i.value().attr("title").unwrap()) .captures(i.value().attr("title").unwrap())
.unwrap(); .unwrap();
@ -76,13 +78,15 @@ pub async fn timetable(
let course = models::Course{ let course = models::Course{
category: match matches category: match matches
.name("type") .name("type")
.unwrap() .map_or("", |m| m.as_str()) {
.as_str() {
"COURS" => [models::Category::Cours].into(), "COURS" => [models::Category::Cours].into(),
"TP" => [models::Category::TP].into(), "TP" | "TP_M2" => [models::Category::TP].into(),
"TD" => [models::Category::TD].into(), "TD" | "TD_M2" => [models::Category::TD].into(),
"COURS_TD" => [models::Category::Cours, 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: matches
.name("name") .name("name")