Compare commits

..

2 commits

Author SHA1 Message Date
d726a7f778
add some parsing 2022-08-13 15:00:34 +02:00
9f2b775601
add day struct 2022-08-13 15:00:22 +02:00
2 changed files with 54 additions and 9 deletions

View file

@ -11,19 +11,56 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let html = include_str!("../target/debug.html"); let html = include_str!("../target/debug.html");
// Parse document // Parse document
let document = Html::parse_document(&html); let document = Html::parse_document(html);
// Selectors
let sel_table = Selector::parse("table").unwrap();
let sel_tr = Selector::parse("tr").unwrap();
let sel_tbody = Selector::parse("tbody").unwrap();
let sel_th = Selector::parse("th").unwrap();
let sel_td = Selector::parse("td").unwrap();
// Find the timetable // Find the timetable
let selector_timetable = Selector::parse("table").unwrap(); let raw_timetable = document.select(&sel_table).next().unwrap();
let raw_timetable = document.select(&selector_timetable).next().unwrap();
//println!("{}", &raw_timetable.inner_html());
// Find the slots available for the timetable // Find the slots available for the timetable
let selector_schedules = Selector::parse("tr").unwrap(); let raw_schedules = raw_timetable.select(&sel_tr).next().unwrap();
let raw_schedules = raw_timetable.select(&selector_schedules).next().unwrap();
println!("{}", &raw_schedules.inner_html());
// Find availables schedules
let mut schedules = Vec::new();
for time in raw_schedules.select(&sel_th) {
schedules.push(time.inner_html());
}
println!("{:#?}", schedules);
// Find the timetable values
let raw_timetable_values = raw_timetable.select(&sel_tbody).next().unwrap();
// For each days
let mut timetable = Vec::new();
for day in raw_timetable_values.select(&sel_tr) {
let mut courses_vec = Vec::new();
for course in day.select(&sel_td) {
if course.inner_html() == "" {
courses_vec.push(None);
} else {
courses_vec.push(Some(models::Course {
professor: "coucou".to_string(),
room: Vec::new(),
start: 0,
size: 1,
}));
}
}
timetable.push(models::Day {
name: day.select(&sel_th).next().unwrap().inner_html(),
courses: courses_vec,
})
}
println!("{:#?}", timetable);
// TODO: Make fn who chacke if timetable is bell built (time consistency)
Ok(()) Ok(())
} }

View file

@ -1,9 +1,10 @@
#[derive(Debug)]
pub struct Course { pub struct Course {
/// Professor's name /// Professor's name
pub professor: String, pub professor: String,
/// List of rooms where the course takes place /// List of rooms where the course takes place
pub room: Box<String>, pub room: Vec<String>,
/// Time the course starts, as a number : /// Time the course starts, as a number :
/// - 0 => first possible class of the day /// - 0 => first possible class of the day
@ -14,3 +15,10 @@ pub struct Course {
/// Number of time slots the course takes up in the timetable /// Number of time slots the course takes up in the timetable
pub size: i8, pub size: i8,
} }
#[derive(Debug)]
pub struct Day {
/// Day's name
pub name: String,
/// Ordered list of all the courses of the day
pub courses: Vec<Option<Course>>,
}