print it lines by line, without table

This commit is contained in:
Mylloon 2024-10-01 18:12:32 +02:00 committed by Mylloon
parent 9f4d90fab0
commit 778a4c52d8
2 changed files with 34 additions and 3 deletions

View file

@ -6,7 +6,7 @@ use scraper::Selector;
use std::{collections::HashMap, sync::Arc};
use crate::utils::{
get_hours, get_semester, get_webpage, get_year,
format_time_slot, get_hours, get_semester, get_webpage, get_year,
models::{Info, InfoList},
Capitalize,
};
@ -270,6 +270,28 @@ fn add_courses(
}
/// Display the timetable
pub fn display(timetable: &(Arc<[String]>, (usize, Vec<models::Day>))) {
todo!("{:#?}", timetable)
pub fn display(timetable: &(Arc<[String]>, (usize, Vec<Day>))) {
for day in &timetable.1 .1 {
for (index, course_option) in day.courses.iter().enumerate() {
if let Some(course) = course_option {
if index == 0 {
println!("\n{}:", day.name);
}
println!(
" {} - {} : {} ({}) // {}",
format_time_slot(course.start, course.size),
course
.category
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(", "),
course.name,
course.room,
course.professor.as_deref().unwrap_or("N/A"),
);
}
}
}
}

View file

@ -161,3 +161,12 @@ pub fn get_count<'a>(
(courses, counts)
}
pub fn format_time_slot(start: usize, size: usize) -> String {
let start_hour = 8 + (start * 15) / 60;
let start_minute = (start * 15) % 60;
let end_hour = start_hour + (size * 15) / 60;
let end_minute = (start_minute + (size * 15)) % 60;
format!("{start_hour:02}h{start_minute:02}-{end_hour:02}h{end_minute:02}")
}