extract extra data from calendar

This commit is contained in:
Mylloon 2024-01-30 14:09:17 +01:00
parent 4791463150
commit 28f2c2b192
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 16 additions and 1 deletions

View file

@ -3,7 +3,9 @@ use std::sync::Arc;
use chrono::TimeZone; use chrono::TimeZone;
use ics::{ use ics::{
parameters, parameters,
properties::{Categories, Class, Description, DtEnd, DtStart, Location, Summary, Transp}, properties::{
Categories, Class, Comment, Description, DtEnd, DtStart, Location, Summary, Transp,
},
Event, ICalendar, Standard, Event, ICalendar, Standard,
}; };
@ -69,6 +71,11 @@ pub fn export(courses: Vec<crate::timetable::models::Course>, filename: &mut Str
// Course's category // Course's category
event.push(Categories::new(categories)); event.push(Categories::new(categories));
// Course extra data
if course.data.is_some() {
event.push(Comment::new(course.data.unwrap()));
}
// Add the course to the calendar // Add the course to the calendar
calendar.add_event(event); calendar.add_event(event);
} }

View file

@ -34,6 +34,7 @@ pub async fn timetable(
let sel_td = Selector::parse("td").unwrap(); let sel_td = Selector::parse("td").unwrap();
let sel_small = Selector::parse("small").unwrap(); let sel_small = Selector::parse("small").unwrap();
let sel_b = Selector::parse("b").unwrap(); let sel_b = Selector::parse("b").unwrap();
let sel_span = Selector::parse("span").unwrap();
// Find the timetable // Find the timetable
let raw_timetable = document.select(&sel_table).next().unwrap(); let raw_timetable = document.select(&sel_table).next().unwrap();
@ -49,6 +50,9 @@ pub async fn timetable(
.select(&sel_td) .select(&sel_td)
.filter(|element| element.value().attr("title").is_some()) .filter(|element| element.value().attr("title").is_some())
.for_each(|i| { .for_each(|i| {
let extra_data = i.select(&sel_span).next().map(|span|
span.inner_html().replace("<br>", "").trim().to_owned()
);
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|TP|COURS_TD) (?P<name>.*) : (?P<day>(lundi|mardi|mercredi|jeudi|vendredi)) (?P<startime>.*) \(durée : (?P<duration>.*)\)")
.unwrap() .unwrap()
@ -98,6 +102,7 @@ pub async fn timetable(
size: i.value().attr("rowspan").unwrap().parse::<usize>().unwrap(), size: i.value().attr("rowspan").unwrap().parse::<usize>().unwrap(),
dtstart: None, dtstart: None,
dtend: None, dtend: None,
data: extra_data,
}; };
// Search for the day in the timetable // Search for the day in the timetable

View file

@ -43,6 +43,9 @@ pub struct Course {
/// Datetime when the course end /// Datetime when the course end
/// Filled only when building for the ICS /// Filled only when building for the ICS
pub dtend: Option<chrono::DateTime<chrono::Utc>>, pub dtend: Option<chrono::DateTime<chrono::Utc>>,
/// Extra data
pub data: Option<String>,
} }
#[derive(Debug)] #[derive(Debug)]