From 6a14d38bceed38b3a7ccc51f81b6cd845548e6b8 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Tue, 27 Nov 2018 10:28:01 -0600 Subject: Read and merge multiple icals --- src/lib.rs | 1 + src/main.rs | 31 +++++++++++++++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 85ba6c0..e754a11 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,3 +11,4 @@ mod errors; pub use calendar::Calendar; pub use date::Date; pub use chrono::Duration; +pub use event::Event; diff --git a/src/main.rs b/src/main.rs index 6d9544b..ce2284d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,19 +3,30 @@ extern crate almanac; use std::env; use std::io::BufReader; use std::fs::File; -use almanac::Duration; -use almanac::Date; + use almanac::Calendar; +use almanac::Date; +use almanac::Duration; +use almanac::Event; fn main() { - let args: Vec<_> = env::args().collect(); - let file = File::open(&args[1]).unwrap(); - let buf = BufReader::new(file); - let calendar = Calendar::parse(buf).unwrap(); + let first = Date::now(); + let last = first + Duration::days(7); - let now = Date::now(); - let events = calendar.get(&now, &(now + Duration::days(1))); - for e in events { - println!("{}", e); + let mut events: Vec<_> = env::args() + .skip(1) + .map(|arg| ics_calendar(&arg, &first, &last)) + .flatten() + .collect(); + events.sort(); + for event in events { + println!("{}", event); } } + +fn ics_calendar(file_path: &str, first: &Date, last: &Date) -> Vec { + let file = File::open(file_path).unwrap(); + let buf = BufReader::new(file); + let calendar = Calendar::parse(buf).unwrap(); + calendar.get(first, last) +} -- cgit v1.2.3