add semester and fix letter issue
This commit is contained in:
parent
c844e4a0c5
commit
5077d6cb38
2 changed files with 16 additions and 4 deletions
|
@ -13,6 +13,10 @@ struct Args {
|
||||||
#[clap(value_parser)]
|
#[clap(value_parser)]
|
||||||
class: String,
|
class: String,
|
||||||
|
|
||||||
|
/// The semester you want (useful only in 3rd year)
|
||||||
|
#[clap(short, long, value_parser)]
|
||||||
|
semester: Option<i8>,
|
||||||
|
|
||||||
/// Export to iCalendar format (.ics)
|
/// Export to iCalendar format (.ics)
|
||||||
#[clap(short, long, action = ArgAction::SetTrue, default_value_t = false)]
|
#[clap(short, long, action = ArgAction::SetTrue, default_value_t = false)]
|
||||||
export: bool,
|
export: bool,
|
||||||
|
@ -42,7 +46,7 @@ async fn main() {
|
||||||
year,
|
year,
|
||||||
letter.unwrap_or_default()
|
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...");
|
println!("Fetch informations about the year...");
|
||||||
let info = info::info().await;
|
let info = info::info().await;
|
||||||
|
|
|
@ -7,9 +7,11 @@ pub mod models;
|
||||||
/// Fetch the timetable for a class
|
/// Fetch the timetable for a class
|
||||||
pub async fn timetable(
|
pub async fn timetable(
|
||||||
year: i8,
|
year: i8,
|
||||||
semester: i8,
|
semester_opt: Option<i8>,
|
||||||
letter: Option<char>,
|
letter: Option<char>,
|
||||||
) -> (Vec<String>, (usize, Vec<models::Day>)) {
|
) -> (Vec<String>, (usize, Vec<models::Day>)) {
|
||||||
|
let semester = get_semester(semester_opt, letter);
|
||||||
|
|
||||||
let document = get_webpage(year, semester, letter)
|
let document = get_webpage(year, semester, letter)
|
||||||
.await
|
.await
|
||||||
.expect("Can't reach timetable website.");
|
.expect("Can't reach timetable website.");
|
||||||
|
@ -123,7 +125,7 @@ async fn get_webpage(
|
||||||
2 => ['x', 'y', 'z'],
|
2 => ['x', 'y', 'z'],
|
||||||
_ => panic!("{}", panic_semester_message),
|
_ => 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) {
|
if allow_letters.contains(&c) {
|
||||||
format!("{}/l1-{}.html", base_url, c)
|
format!("{}/l1-{}.html", base_url, c)
|
||||||
} else {
|
} else {
|
||||||
|
@ -136,7 +138,7 @@ async fn get_webpage(
|
||||||
2 => ['x', 'y'],
|
2 => ['x', 'y'],
|
||||||
_ => panic!("{}", panic_semester_message),
|
_ => 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) {
|
if allow_letters.contains(&c) {
|
||||||
format!("{}/l2-{}.html", base_url, c)
|
format!("{}/l2-{}.html", base_url, c)
|
||||||
} else {
|
} else {
|
||||||
|
@ -279,3 +281,9 @@ pub fn build(timetable: T, dates: D) -> Vec<models::Course> {
|
||||||
|
|
||||||
semester
|
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
|
||||||
|
}
|
||||||
|
|
Reference in a new issue