From 6e139369801c6fef5cc392489a876e56631024f4 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 29 Sep 2023 00:03:41 +0200 Subject: [PATCH] fill hours is useful for the filter --- src/timetable.rs | 15 ++------------- src/utils.rs | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/timetable.rs b/src/timetable.rs index bc02809..32bd650 100644 --- a/src/timetable.rs +++ b/src/timetable.rs @@ -4,7 +4,7 @@ use scraper::Selector; use std::collections::HashMap; use crate::utils::{ - self, get_semester, get_webpage, get_year, + self, fill_hours, get_semester, get_webpage, get_year, models::{Position, TabChar}, Capitalize, }; @@ -37,18 +37,7 @@ pub async fn timetable( let raw_timetable = document.select(&sel_table).next().unwrap(); let mut schedules = Vec::new(); - 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) = schedules.pop() { - schedules.push(format!("{}-{}", last_hour, hour_str)); - } - schedules.push(hour_str); - } - } - for _ in 0..4 { - schedules.pop(); - } + fill_hours(&mut schedules); let mut timetable: Vec = Vec::new(); diff --git a/src/utils.rs b/src/utils.rs index b6a2ffa..d5ca354 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -179,3 +179,18 @@ impl Capitalize for str { string } } + +pub fn fill_hours(hours: &mut Vec) { + 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(); + } +}