Browse Source

uniquify events

master
Astro 2 years ago
parent
commit
e7b024e843
  1. 12
      src/main.rs

12
src/main.rs

@ -5,7 +5,7 @@ use std::mem::replace;
use std::io::Read;
use std::fs::read_to_string;
use std::sync::RwLock;
use std::collections::VecDeque;
use std::collections::{HashMap, VecDeque};
use chrono::offset::Utc;
use reqwest::header::{IF_NONE_MATCH, IF_MODIFIED_SINCE, ETAG, LAST_MODIFIED, USER_AGENT};
use diesel::{Connection, pg::PgConnection, prelude::*};
@ -146,7 +146,7 @@ impl Resources {
let mut p = Parser::new();
let mut buf = [0; 1024];
let mut events = vec![];
let mut events = HashMap::new();
loop {
match res.read(&mut buf)? {
len if len > 0 => {
@ -156,8 +156,8 @@ impl Resources {
extract_vevent_objs(&mut objs, obj);
for obj in objs {
let dbg = format!("{:?}", obj);
if let Some(event) = obj_to_event(cal_opts.url.clone(), obj) {
events.push(event);
if let Some(event) = obj_to_event(cal_opts.url.clone(), &obj) {
events.insert(event.id.clone(), event);
} else {
println!("ignore {}", dbg);
}
@ -173,9 +173,9 @@ impl Resources {
diesel::delete(schema::events::dsl::events)
.filter(schema::events::dsl::calendar.eq(cal_opts.url))
.execute(&db)?;
for event in events {
for event in events.values() {
diesel::insert_into(schema::events::dsl::events)
.values(&event)
.values(event)
.execute(&db)?;
}

Loading…
Cancel
Save