Ver código fonte

ticker-update: feed EXDATE/EXRULE/RDATE to rrule

master
Astro 4 meses atrás
pai
commit
6f95611155
  1. 16
      libticker/src/ics/mod.rs
  2. 23
      ticker-update/src/main.rs

16
libticker/src/ics/mod.rs

@ -22,7 +22,21 @@ pub struct Object {
impl<'a> GetValue<'a, &'a str> for Object {
fn get(&'a self, key: &'_ str) -> Option<&'a str> {
self.content.get(key)
.and_then(|pairs| pairs.first().map(|(_props, ref value)| value.as_str()))
.and_then(|pairs| pairs.first().map(|(_props, value)| value.as_str()))
}
}
impl<'a> GetValue<'a, &'a (Props, String)> for Object {
fn get(&'a self, key: &'_ str) -> Option<&'a (Props, String)> {
self.content.get(key)
.and_then(|pairs| pairs.first())
}
}
impl<'a> GetValue<'a, &'a [(Props, String)]> for Object {
fn get(&'a self, key: &'_ str) -> Option<&'a [(Props, String)]> {
self.content.get(key)
.map(|data| data.as_slice())
}
}

23
ticker-update/src/main.rs

@ -64,10 +64,25 @@ fn obj_to_events(calendar: String, obj: &Object) -> Vec<Event> {
};
let rrule_str: Option<&str> = obj.get("RRULE");
let rrule = rrule_str.and_then(
|rrule_str| RRule::from_str(
&format!("DTSTART:{}\nRRULE:{}", dtstart_str, rrule_str)
).map_err(|e| println!("Error parsing RRULE: {}", e))
let rrule = rrule_str.map(|rrule_str|
format!("DTSTART:{}\nRRULE:{}", dtstart_str, rrule_str)
).map(|mut s| {
for exdate in obj.get("EXDATE")
.unwrap_or(&[][..]) {
s = format!("{}\nEXDATE:{}", s, exdate.1);
}
for exrule in obj.get("EXRULE")
.unwrap_or(&[][..]) {
s = format!("{}\nEXRULE:{}", s, exrule.1);
}
for rdate in obj.get("RDATE")
.unwrap_or(&[][..]) {
s = format!("{}\nRDATE:{}", s, rdate.1);
}
s
}).and_then(|s|
RRule::from_str(&s)
.map_err(|e| println!("Error parsing RRULE: {}", e))
.ok()
);
match rrule {

Carregando…
Cancelar
Salvar