Compare commits
2 commits
ea9c271b2c
...
b1adad3519
Author | SHA1 | Date | |
---|---|---|---|
b1adad3519 | |||
182933226e |
2 changed files with 23 additions and 10 deletions
|
@ -57,7 +57,12 @@ pub fn export(courses: Vec<crate::timetable::models::Course>, filename: &str) {
|
|||
calendar.add_event(event);
|
||||
}
|
||||
|
||||
calendar.save_file(filename).unwrap();
|
||||
calendar
|
||||
.save_file(match filename.to_string() {
|
||||
x if x.ends_with(".ics") => x,
|
||||
x => format!("{}.ics", x),
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
/// Transform the datetime from chrono to the ICS format
|
||||
|
|
26
src/main.rs
26
src/main.rs
|
@ -1,4 +1,4 @@
|
|||
use clap::{ArgAction, Parser};
|
||||
use clap::Parser;
|
||||
use regex::Regex;
|
||||
|
||||
mod ics;
|
||||
|
@ -9,17 +9,17 @@ mod utils;
|
|||
#[derive(Parser)]
|
||||
#[clap(version, about, long_about = None)]
|
||||
struct Args {
|
||||
/// The class you want to get the timetable
|
||||
/// The class you want to get the timetable, i.e.: L2-A
|
||||
#[clap(value_parser)]
|
||||
class: String,
|
||||
|
||||
/// The semester you want (useful only in 3rd year)
|
||||
#[clap(short, long, value_parser)]
|
||||
/// The semester you want (useful only in 3rd year, 1-2 use letter in class)
|
||||
#[clap(short, long, value_parser, value_name = "SEMESTER NUMBER")]
|
||||
semester: Option<i8>,
|
||||
|
||||
/// Export to iCalendar format (.ics)
|
||||
#[clap(short, long, action = ArgAction::SetTrue, default_value_t = false)]
|
||||
export: bool,
|
||||
#[clap(short, long, value_name = "FILE NAME")]
|
||||
export: Option<String>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
@ -51,8 +51,16 @@ async fn main() {
|
|||
println!("Fetch informations about the year...");
|
||||
let info = info::info().await;
|
||||
|
||||
println!("Build the ICS file...");
|
||||
let builded_timetable = timetable::build(timetable, info);
|
||||
if args.export.is_some() {
|
||||
// Export the calendar
|
||||
|
||||
ics::export(builded_timetable, "target/debug.ics");
|
||||
let filename = args.export.unwrap();
|
||||
println!("Build the ICS file at {}...", filename);
|
||||
|
||||
let builded_timetable = timetable::build(timetable, info);
|
||||
ics::export(builded_timetable, &filename);
|
||||
} else {
|
||||
// Show the calendar
|
||||
println!("Displaying...")
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue