Archived
1
0
Fork 0
forked from Anri/cal8tor
This repository has been archived on 2023-04-23. You can view files and clone it, but cannot push or open issues or pull requests.
cal8tor/src/main.rs

55 lines
1.3 KiB
Rust
Raw Normal View History

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;
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 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()
);
let timetable = timetable::timetable(year, 1, 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...");
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
}