cherry-pick of Paris8/cal8tor:0a5dd3c8f007ee69b720c40d9a761f4d0df6f19d

This commit is contained in:
Mylloon 2023-04-23 00:22:19 +02:00
parent a45d40dafa
commit 7380364c1c
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 13 additions and 12 deletions

2
Cargo.lock generated
View file

@ -70,7 +70,7 @@ checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c"
[[package]]
name = "cal8tor"
version = "0.4.2"
version = "0.4.3"
dependencies = [
"chrono",
"clap",

View file

@ -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"

View file

@ -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

View file

@ -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...");