forked from Anri/cal8tor
return the new filename for verbose
This commit is contained in:
parent
09a83c2b66
commit
0a5dd3c8f0
4 changed files with 13 additions and 12 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -70,7 +70,7 @@ checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c"
|
|||
|
||||
[[package]]
|
||||
name = "cal8tor"
|
||||
version = "0.4.2"
|
||||
version = "0.4.3"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"clap",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "cal8tor"
|
||||
version = "0.4.2"
|
||||
version = "0.4.3"
|
||||
authors = ["Mylloon"]
|
||||
edition = "2021"
|
||||
description = "Extractor of the calendar of the IT degree of university Paris 8"
|
||||
|
|
14
src/ics.rs
14
src/ics.rs
|
@ -5,7 +5,7 @@ use ics::{
|
|||
Event, ICalendar, Standard,
|
||||
};
|
||||
|
||||
pub fn export(courses: Vec<crate::timetable::models::Course>, filename: String) {
|
||||
pub fn export(courses: Vec<crate::timetable::models::Course>, filename: &mut String) {
|
||||
let mut calendar = ICalendar::new("2.0", "cal8tor");
|
||||
|
||||
// Add Europe/Paris timezone
|
||||
|
@ -61,12 +61,12 @@ pub fn export(courses: Vec<crate::timetable::models::Course>, filename: String)
|
|||
calendar.add_event(event);
|
||||
}
|
||||
|
||||
calendar
|
||||
.save_file(match filename {
|
||||
x if x.ends_with(".ics") => x,
|
||||
x => format!("{}.ics", x),
|
||||
})
|
||||
.unwrap();
|
||||
// Add the extension if needed
|
||||
if !filename.ends_with(".ics") {
|
||||
*filename = format!("{}.ics", filename)
|
||||
};
|
||||
|
||||
calendar.save_file(filename).unwrap();
|
||||
}
|
||||
|
||||
/// Transform the datetime from chrono to the ICS format
|
||||
|
|
|
@ -66,11 +66,12 @@ async fn main() {
|
|||
|
||||
if args.export.is_some() {
|
||||
// Export the calendar
|
||||
let filename = args.export.unwrap();
|
||||
println!("Fichier .ICS construit et exporté ici : {}...", filename);
|
||||
let mut filename = args.export.unwrap();
|
||||
|
||||
let builded_timetable = timetable::build(timetable, info);
|
||||
ics::export(builded_timetable, filename);
|
||||
ics::export(builded_timetable, &mut filename);
|
||||
|
||||
println!("Fichier .ICS construit et exporté => {}", filename);
|
||||
} else {
|
||||
// Show the calendar
|
||||
println!("Affichage...");
|
||||
|
|
Reference in a new issue