forked from Anri/cal8tor
* Parse the timetable completly
* Verification of the builded timetable
This commit is contained in:
parent
db1a301258
commit
a3f8959145
1 changed files with 63 additions and 15 deletions
72
src/main.rs
72
src/main.rs
|
@ -19,6 +19,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let sel_tbody = Selector::parse("tbody").unwrap();
|
let sel_tbody = Selector::parse("tbody").unwrap();
|
||||||
let sel_th = Selector::parse("th").unwrap();
|
let sel_th = Selector::parse("th").unwrap();
|
||||||
let sel_td = Selector::parse("td").unwrap();
|
let sel_td = Selector::parse("td").unwrap();
|
||||||
|
let sel_em = Selector::parse("em").unwrap();
|
||||||
|
let sel_small = Selector::parse("small").unwrap();
|
||||||
|
let sel_strong = Selector::parse("strong").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();
|
||||||
|
@ -39,18 +42,48 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let mut timetable = Vec::new();
|
let mut timetable = Vec::new();
|
||||||
for day in raw_timetable_values.select(&sel_tr) {
|
for day in raw_timetable_values.select(&sel_tr) {
|
||||||
let mut courses_vec = Vec::new();
|
let mut courses_vec = Vec::new();
|
||||||
|
let mut location_tracker = 0;
|
||||||
for course in day.select(&sel_td) {
|
for course in day.select(&sel_td) {
|
||||||
if course.inner_html() == "—" {
|
if course.inner_html() == "—" {
|
||||||
courses_vec.push(None);
|
courses_vec.push(None);
|
||||||
|
location_tracker += 1;
|
||||||
} else {
|
} else {
|
||||||
courses_vec.push(Some(models::Course {
|
courses_vec.push(Some(models::Course {
|
||||||
professor: "coucou".to_string(),
|
name: course.select(&sel_em).next().unwrap().inner_html(),
|
||||||
room: Vec::new(),
|
professor: match course
|
||||||
start: 0,
|
.select(&sel_small)
|
||||||
size: 1,
|
.next()
|
||||||
|
.unwrap()
|
||||||
|
.inner_html()
|
||||||
|
.split("<br>")
|
||||||
|
.next()
|
||||||
|
{
|
||||||
|
Some(data) => {
|
||||||
|
if data.contains("</strong>") {
|
||||||
|
// This is the room, so there is no professor assigned
|
||||||
|
// to this courses yet
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(data.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => None,
|
||||||
|
},
|
||||||
|
room: course.select(&sel_strong).next().unwrap().inner_html(),
|
||||||
|
start: location_tracker,
|
||||||
|
size: match course.value().attr("colspan") {
|
||||||
|
Some(i) => i.parse().unwrap(),
|
||||||
|
None => 1,
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
match &courses_vec[courses_vec.len() - 1] {
|
||||||
|
Some(course) => location_tracker += course.size,
|
||||||
|
None => location_tracker += 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
println!("\n");
|
||||||
|
|
||||||
timetable.push(models::Day {
|
timetable.push(models::Day {
|
||||||
name: day.select(&sel_th).next().unwrap().inner_html(),
|
name: day.select(&sel_th).next().unwrap().inner_html(),
|
||||||
|
@ -68,14 +101,29 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
/// Check if the timetable is well built
|
/// Check if the timetable is well built
|
||||||
fn check_timetable_consistency(schedules: &Vec<String>, timetable: &Vec<models::Day>) -> bool {
|
fn check_timetable_consistency(schedules: &Vec<String>, timetable: &Vec<models::Day>) -> bool {
|
||||||
// No work during week-end
|
let mut checker = true;
|
||||||
if timetable.len() == 5 {
|
for day in timetable {
|
||||||
// TODO: Check if schedules.len() is coherent
|
let mut i = 0;
|
||||||
// with the values inside the timetable
|
for course in &day.courses {
|
||||||
println!("{:#?}", schedules);
|
match course {
|
||||||
println!("{:#?}", timetable);
|
Some(course_it) => {
|
||||||
return true;
|
// Checks the consistency of course start times
|
||||||
|
if i != course_it.start {
|
||||||
|
checker = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Keep the track of how many courses are in the day
|
||||||
|
i += course_it.size
|
||||||
|
}
|
||||||
|
None => i += 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The counter should be the same as the amount of possible hours of the day
|
||||||
|
if i != schedules.len() {
|
||||||
|
checker = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
false
|
checker
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue