From 20fd40bbba6343ded8e8ade5fa9d66a2ac7d9a2f Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 30 Aug 2022 22:52:44 +0200 Subject: [PATCH] support for l3-a and l3-b --- src/timetable.rs | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/timetable.rs b/src/timetable.rs index a36341d..d30fa40 100644 --- a/src/timetable.rs +++ b/src/timetable.rs @@ -132,38 +132,41 @@ async fn get_webpage( let panic_letter_message = "Unknown letter."; let base_url = "https://informatique.up8.edu/licence-iv/edt"; + let allow_letters_1 = match semester { + 1 => ['a', 'b', 'c'], + 2 => ['x', 'y', 'z'], + _ => panic!("{}", panic_semester_message), + }; + let allow_letters_2_3 = match semester { + 1 => ['a', 'b'], + 2 => ['x', 'y'], + _ => panic!("{}", panic_semester_message), + }; match year { 1 => { - let allow_letters = match semester { - 1 => ['a', 'b', 'c'], - 2 => ['x', 'y', 'z'], - _ => panic!("{}", panic_semester_message), - }; let c = letter.expect(panic_letter_message).to_ascii_lowercase(); - if allow_letters.contains(&c) { + if allow_letters_1.contains(&c) { format!("{}/l1-{}.html", base_url, c) } else { panic!("{}", panic_letter_message) } } 2 => { - let allow_letters = match semester { - 1 => ['a', 'b'], - 2 => ['x', 'y'], - _ => panic!("{}", panic_semester_message), - }; let c = letter.expect(panic_letter_message).to_ascii_lowercase(); - if allow_letters.contains(&c) { + if allow_letters_2_3.contains(&c) { format!("{}/l2-{}.html", base_url, c) } else { panic!("{}", panic_letter_message) } } - 3 => match semester { - 1 => format!("{}/l3.html", base_url), - 2 => format!("{}/l3_2.html", base_url), - _ => panic!("{}", panic_semester_message), - }, + 3 => { + let c = letter.expect(panic_letter_message).to_ascii_lowercase(); + if allow_letters_2_3.contains(&c) { + format!("{}/l3-{}.html", base_url, c) + } else { + panic!("{}", panic_letter_message) + } + } _ => panic!("Unknown year."), } };