forked from Anri/cal8tor
fill hours is useful for the filter
This commit is contained in:
parent
041b8625f1
commit
6e13936980
2 changed files with 17 additions and 13 deletions
|
@ -4,7 +4,7 @@ use scraper::Selector;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
self, get_semester, get_webpage, get_year,
|
self, fill_hours, get_semester, get_webpage, get_year,
|
||||||
models::{Position, TabChar},
|
models::{Position, TabChar},
|
||||||
Capitalize,
|
Capitalize,
|
||||||
};
|
};
|
||||||
|
@ -37,18 +37,7 @@ pub async fn timetable(
|
||||||
let raw_timetable = document.select(&sel_table).next().unwrap();
|
let raw_timetable = document.select(&sel_table).next().unwrap();
|
||||||
|
|
||||||
let mut schedules = Vec::new();
|
let mut schedules = Vec::new();
|
||||||
for hour in 8..=20 {
|
fill_hours(&mut schedules);
|
||||||
for minute in &[0, 15, 30, 45] {
|
|
||||||
let hour_str = format!("{}h{:02}", hour, minute);
|
|
||||||
if let Some(last_hour) = schedules.pop() {
|
|
||||||
schedules.push(format!("{}-{}", last_hour, hour_str));
|
|
||||||
}
|
|
||||||
schedules.push(hour_str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _ in 0..4 {
|
|
||||||
schedules.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut timetable: Vec<models::Day> = Vec::new();
|
let mut timetable: Vec<models::Day> = Vec::new();
|
||||||
|
|
||||||
|
|
15
src/utils.rs
15
src/utils.rs
|
@ -179,3 +179,18 @@ impl Capitalize for str {
|
||||||
string
|
string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn fill_hours(hours: &mut Vec<String>) {
|
||||||
|
for hour in 8..=20 {
|
||||||
|
for minute in &[0, 15, 30, 45] {
|
||||||
|
let hour_str = format!("{}h{:02}", hour, minute);
|
||||||
|
if let Some(last_hour) = hours.pop() {
|
||||||
|
hours.push(format!("{}-{}", last_hour, hour_str));
|
||||||
|
}
|
||||||
|
hours.push(hour_str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _ in 0..4 {
|
||||||
|
hours.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue