From 778a4c52d83ec6ac67ac851e6c721151ac970289 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 1 Oct 2024 18:12:32 +0200 Subject: [PATCH] print it lines by line, without table --- src/timetable.rs | 28 +++++++++++++++++++++++++--- src/utils.rs | 9 +++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/timetable.rs b/src/timetable.rs index 94b38c3..3fcf200 100644 --- a/src/timetable.rs +++ b/src/timetable.rs @@ -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))) { - todo!("{:#?}", timetable) +pub fn display(timetable: &(Arc<[String]>, (usize, Vec))) { + 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::>() + .join(", "), + course.name, + course.room, + course.professor.as_deref().unwrap_or("N/A"), + ); + } + } + } } diff --git a/src/utils.rs b/src/utils.rs index e15525a..47bd609 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -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}") +}