From 5077d6cb38ab064d2bcb21c7c3e9ce994278204b Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 17 Aug 2022 14:09:08 +0200 Subject: [PATCH] add semester and fix letter issue --- src/main.rs | 6 +++++- src/timetable.rs | 14 +++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4b1f3ec..0bb897d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,10 @@ struct Args { #[clap(value_parser)] class: String, + /// The semester you want (useful only in 3rd year) + #[clap(short, long, value_parser)] + semester: Option, + /// Export to iCalendar format (.ics) #[clap(short, long, action = ArgAction::SetTrue, default_value_t = false)] export: bool, @@ -42,7 +46,7 @@ async fn main() { year, letter.unwrap_or_default() ); - let timetable = timetable::timetable(year, 1, letter).await; + let timetable = timetable::timetable(year, args.semester, letter).await; println!("Fetch informations about the year..."); let info = info::info().await; diff --git a/src/timetable.rs b/src/timetable.rs index 036d9da..e79c96a 100644 --- a/src/timetable.rs +++ b/src/timetable.rs @@ -7,9 +7,11 @@ pub mod models; /// Fetch the timetable for a class pub async fn timetable( year: i8, - semester: i8, + semester_opt: Option, letter: Option, ) -> (Vec, (usize, Vec)) { + let semester = get_semester(semester_opt, letter); + let document = get_webpage(year, semester, letter) .await .expect("Can't reach timetable website."); @@ -123,7 +125,7 @@ async fn get_webpage( 2 => ['x', 'y', 'z'], _ => panic!("{}", panic_semester_message), }; - let c = letter.expect(panic_letter_message); + let c = letter.expect(panic_letter_message).to_ascii_lowercase(); if allow_letters.contains(&c) { format!("{}/l1-{}.html", base_url, c) } else { @@ -136,7 +138,7 @@ async fn get_webpage( 2 => ['x', 'y'], _ => panic!("{}", panic_semester_message), }; - let c = letter.expect(panic_letter_message); + let c = letter.expect(panic_letter_message).to_ascii_lowercase(); if allow_letters.contains(&c) { format!("{}/l2-{}.html", base_url, c) } else { @@ -279,3 +281,9 @@ pub fn build(timetable: T, dates: D) -> Vec { semester } + +/// Get the current semester depending on the letter or the current date +fn get_semester(_semester: Option, _letter: Option) -> i8 { + // TODO + 1 +}