2022-08-17 12:21:56 +02:00
|
|
|
use clap::{ArgAction, Parser};
|
|
|
|
use regex::Regex;
|
2022-08-16 23:40:42 +02:00
|
|
|
|
2022-08-16 10:32:46 +02:00
|
|
|
mod ics;
|
2022-08-16 10:41:42 +02:00
|
|
|
mod info;
|
2022-08-15 14:52:57 +02:00
|
|
|
mod timetable;
|
2022-08-16 15:48:13 +02:00
|
|
|
mod utils;
|
2022-08-12 21:20:39 +02:00
|
|
|
|
2022-08-16 23:40:42 +02:00
|
|
|
#[derive(Parser)]
|
|
|
|
#[clap(version, about, long_about = None)]
|
|
|
|
struct Args {
|
2022-08-17 12:21:56 +02:00
|
|
|
/// The class you want to get the timetable
|
|
|
|
#[clap(value_parser)]
|
|
|
|
class: String,
|
2022-08-16 23:40:42 +02:00
|
|
|
|
2022-08-17 14:09:08 +02:00
|
|
|
/// The semester you want (useful only in 3rd year)
|
|
|
|
#[clap(short, long, value_parser)]
|
|
|
|
semester: Option<i8>,
|
|
|
|
|
2022-08-17 12:21:56 +02:00
|
|
|
/// Export to iCalendar format (.ics)
|
|
|
|
#[clap(short, long, action = ArgAction::SetTrue, default_value_t = false)]
|
|
|
|
export: bool,
|
2022-08-16 23:40:42 +02:00
|
|
|
}
|
|
|
|
|
2022-08-12 19:55:28 +02:00
|
|
|
#[tokio::main]
|
2022-08-14 12:44:36 +02:00
|
|
|
async fn main() {
|
2022-08-16 23:40:42 +02:00
|
|
|
let args = Args::parse();
|
|
|
|
|
2022-08-17 12:21:56 +02:00
|
|
|
let matches = Regex::new(r"[Ll](?P<year>\d)-?(?P<letter>.)?")
|
|
|
|
.unwrap()
|
|
|
|
.captures(&args.class)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let year = matches
|
|
|
|
.name("year")
|
|
|
|
.unwrap()
|
|
|
|
.as_str()
|
|
|
|
.parse::<i8>()
|
|
|
|
.unwrap();
|
|
|
|
let letter = matches
|
|
|
|
.name("letter")
|
|
|
|
.map(|c| c.as_str().chars().next().expect("Error in letter"));
|
|
|
|
|
|
|
|
println!(
|
|
|
|
"Fetch the timetable for L{}{}...",
|
|
|
|
year,
|
|
|
|
letter.unwrap_or_default()
|
|
|
|
);
|
2022-08-17 14:09:08 +02:00
|
|
|
let timetable = timetable::timetable(year, args.semester, letter).await;
|
2022-08-12 21:20:39 +02:00
|
|
|
|
2022-08-16 15:48:13 +02:00
|
|
|
println!("Fetch informations about the year...");
|
2022-08-15 19:20:10 +02:00
|
|
|
let info = info::info().await;
|
|
|
|
|
2022-08-16 15:48:13 +02:00
|
|
|
println!("Build the ICS file...");
|
2022-08-16 10:41:42 +02:00
|
|
|
let builded_timetable = timetable::build(timetable, info);
|
|
|
|
|
2022-08-17 12:21:56 +02:00
|
|
|
ics::export(builded_timetable, "target/debug.ics");
|
2022-08-14 12:44:36 +02:00
|
|
|
}
|