From 28f2c2b19219a7ac765c0a402c05b7f107584555 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 30 Jan 2024 14:09:17 +0100 Subject: [PATCH] extract extra data from calendar --- src/ics.rs | 9 ++++++++- src/timetable.rs | 5 +++++ src/timetable/models.rs | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ics.rs b/src/ics.rs index 0e39e3d..2133bbf 100644 --- a/src/ics.rs +++ b/src/ics.rs @@ -3,7 +3,9 @@ use std::sync::Arc; use chrono::TimeZone; use ics::{ parameters, - properties::{Categories, Class, Description, DtEnd, DtStart, Location, Summary, Transp}, + properties::{ + Categories, Class, Comment, Description, DtEnd, DtStart, Location, Summary, Transp, + }, Event, ICalendar, Standard, }; @@ -69,6 +71,11 @@ pub fn export(courses: Vec, filename: &mut Str // Course's category 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 calendar.add_event(event); } diff --git a/src/timetable.rs b/src/timetable.rs index 00a9140..5448e97 100644 --- a/src/timetable.rs +++ b/src/timetable.rs @@ -34,6 +34,7 @@ pub async fn timetable( let sel_td = Selector::parse("td").unwrap(); let sel_small = Selector::parse("small").unwrap(); let sel_b = Selector::parse("b").unwrap(); + let sel_span = Selector::parse("span").unwrap(); // Find the timetable let raw_timetable = document.select(&sel_table).next().unwrap(); @@ -49,6 +50,9 @@ pub async fn timetable( .select(&sel_td) .filter(|element| element.value().attr("title").is_some()) .for_each(|i| { + let extra_data = i.select(&sel_span).next().map(|span| + span.inner_html().replace("
", "").trim().to_owned() + ); let matches = Regex::new(r"(?PCOURS|TD|TP|COURS_TD) (?P.*) : (?P(lundi|mardi|mercredi|jeudi|vendredi)) (?P.*) \(durée : (?P.*)\)") .unwrap() @@ -98,6 +102,7 @@ pub async fn timetable( size: i.value().attr("rowspan").unwrap().parse::().unwrap(), dtstart: None, dtend: None, + data: extra_data, }; // Search for the day in the timetable diff --git a/src/timetable/models.rs b/src/timetable/models.rs index d55e705..3939098 100644 --- a/src/timetable/models.rs +++ b/src/timetable/models.rs @@ -43,6 +43,9 @@ pub struct Course { /// Datetime when the course end /// Filled only when building for the ICS pub dtend: Option>, + + /// Extra data + pub data: Option, } #[derive(Debug)]