2022-08-17 14:56:36 +02:00
|
|
|
use clap::Parser;
|
2022-08-17 12:21:56 +02:00
|
|
|
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 14:56:36 +02:00
|
|
|
/// The class you want to get the timetable, i.e.: L2-A
|
2022-08-17 12:21:56 +02:00
|
|
|
#[clap(value_parser)]
|
|
|
|
class: String,
|
2022-08-16 23:40:42 +02:00
|
|
|
|
2022-08-17 14:56:36 +02:00
|
|
|
/// The semester you want (useful only in 3rd year, 1-2 use letter in class)
|
|
|
|
#[clap(short, long, value_parser, value_name = "SEMESTER NUMBER")]
|
2022-08-17 14:09:08 +02:00
|
|
|
semester: Option<i8>,
|
|
|
|
|
2022-08-17 12:21:56 +02:00
|
|
|
/// Export to iCalendar format (.ics)
|
2022-08-17 14:56:36 +02:00
|
|
|
#[clap(short, long, value_name = "FILE NAME")]
|
2022-08-17 14:38:31 +02:00
|
|
|
export: Option<String>,
|
2022-08-23 18:38:47 +02:00
|
|
|
|
|
|
|
/// Size of cell of the timetable (irrelevant when exporting the timetable)
|
|
|
|
#[clap(short, long, value_name = "CELL LENGTH", default_value_t = 35)]
|
|
|
|
cl: usize,
|
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 16:58:49 +02:00
|
|
|
let matches = Regex::new(r"[Ll](?P<year>\d)[-–•·]?(?P<letter>.)?")
|
2022-08-17 12:21:56 +02:00
|
|
|
.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"));
|
|
|
|
|
2022-08-23 10:28:30 +02:00
|
|
|
// Show a separator only if we need one
|
|
|
|
let seperator = match letter {
|
|
|
|
Some(_) => "-",
|
|
|
|
None => "",
|
|
|
|
};
|
|
|
|
|
2022-08-17 12:21:56 +02:00
|
|
|
println!(
|
2022-08-23 15:17:12 +02:00
|
|
|
"Récupération de l'emploi du temps des L{}{}{}...",
|
2022-08-17 12:21:56 +02:00
|
|
|
year,
|
2022-08-23 10:28:30 +02:00
|
|
|
seperator,
|
2022-08-23 10:29:15 +02:00
|
|
|
letter.unwrap_or_default().to_uppercase()
|
2022-08-17 12:21:56 +02:00
|
|
|
);
|
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-23 15:17:12 +02:00
|
|
|
println!("Récupération des informations par rapport à l'année...");
|
2022-08-15 19:20:10 +02:00
|
|
|
let info = info::info().await;
|
|
|
|
|
2022-08-17 14:38:31 +02:00
|
|
|
if args.export.is_some() {
|
|
|
|
// Export the calendar
|
2022-08-17 14:56:36 +02:00
|
|
|
let filename = args.export.unwrap();
|
2022-08-23 15:17:12 +02:00
|
|
|
println!("Fichier .ICS construit et exporté ici : {}...", filename);
|
2022-08-17 14:56:36 +02:00
|
|
|
|
|
|
|
let builded_timetable = timetable::build(timetable, info);
|
2022-08-17 17:08:30 +02:00
|
|
|
ics::export(builded_timetable, filename);
|
2022-08-17 14:38:31 +02:00
|
|
|
} else {
|
|
|
|
// Show the calendar
|
2022-08-23 15:17:12 +02:00
|
|
|
println!("Affichage...");
|
2022-08-23 18:38:47 +02:00
|
|
|
timetable::display(timetable, args.cl);
|
2022-08-23 15:17:12 +02:00
|
|
|
println!("Vous devrez peut-être mettre votre terminal en plein écran si ce n'est pas déjà le cas.");
|
2022-08-17 14:38:31 +02:00
|
|
|
}
|
2022-08-14 12:44:36 +02:00
|
|
|
}
|