add semester and fix letter issue

This commit is contained in:
Mylloon 2022-08-17 14:09:08 +02:00
parent c844e4a0c5
commit 5077d6cb38
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 16 additions and 4 deletions

View file

@ -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<i8>,
/// 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;

View file

@ -7,9 +7,11 @@ pub mod models;
/// Fetch the timetable for a class
pub async fn timetable(
year: i8,
semester: i8,
semester_opt: Option<i8>,
letter: Option<char>,
) -> (Vec<String>, (usize, Vec<models::Day>)) {
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<models::Course> {
semester
}
/// Get the current semester depending on the letter or the current date
fn get_semester(_semester: Option<i8>, _letter: Option<char>) -> i8 {
// TODO
1
}