split ticker-update into libticker

This commit is contained in:
Astro 2019-10-26 00:19:25 +02:00
parent b5f731aefe
commit db76004e82
11 changed files with 36 additions and 11 deletions

11
Cargo.lock generated
View File

@ -503,6 +503,16 @@ name = "libc"
version = "0.2.62" version = "0.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libticker"
version = "0.1.0"
dependencies = [
"chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "linked-hash-map" name = "linked-hash-map"
version = "0.5.2" version = "0.5.2"
@ -1169,6 +1179,7 @@ dependencies = [
"chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libticker 0.1.0",
"num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.21 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.21 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",

11
libticker/Cargo.toml Normal file
View File

@ -0,0 +1,11 @@
[package]
name = "libticker"
version = "0.1.0"
authors = ["Astro <astro@spaceboyz.net>"]
edition = "2018"
[dependencies]
diesel = { version = "~1", features = ["postgres", "chrono"] }
chrono = "~0.4"
serde = { version = "~1.0", features = ["derive"] }
serde_yaml = "~0.8"

7
libticker/src/lib.rs Normal file
View File

@ -0,0 +1,7 @@
#[macro_use]
extern crate diesel;
pub mod config;
pub mod ics;
pub mod model;
pub mod schema;

View File

@ -12,3 +12,4 @@ serde = { version = "~1.0", features = ["derive"] }
serde_yaml = "~0.8" serde_yaml = "~0.8"
num_cpus = "~1" num_cpus = "~1"
crossbeam = "~0.7" crossbeam = "~0.7"
libticker = { path = "../libticker" }

View File

@ -1,6 +1,3 @@
#[macro_use]
extern crate diesel;
use std::mem::replace; use std::mem::replace;
use std::io::Read; use std::io::Read;
use std::fs::read_to_string; use std::fs::read_to_string;
@ -10,14 +7,12 @@ use chrono::offset::Utc;
use reqwest::header::{IF_NONE_MATCH, IF_MODIFIED_SINCE, ETAG, LAST_MODIFIED, USER_AGENT}; use reqwest::header::{IF_NONE_MATCH, IF_MODIFIED_SINCE, ETAG, LAST_MODIFIED, USER_AGENT};
use diesel::{Connection, pg::PgConnection, prelude::*}; use diesel::{Connection, pg::PgConnection, prelude::*};
mod config; use libticker::{
use config::{Config, CalendarOptions}; config::{Config, CalendarOptions},
mod schema; schema::{self, calendars::dsl::calendars},
use schema::{calendars::dsl::calendars}; model::{Calendar, NewCalendar, Event},
mod model; ics::{Parser, Object, Timestamp, GetValue},
use model::{Calendar, NewCalendar, Event}; };
mod ics;
use ics::{Parser, Object, Timestamp, GetValue};
fn extract_vevent_objs(results: &mut Vec<Object>, mut obj: Object) { fn extract_vevent_objs(results: &mut Vec<Object>, mut obj: Object) {
let children = replace(&mut obj.children, vec![]); let children = replace(&mut obj.children, vec![]);