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