event_parser WIP: compiles successfully

This commit is contained in:
Sean McNamara 2022-11-30 09:28:31 -05:00
parent 042456eced
commit c5c64d6772
7 changed files with 68 additions and 103 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@
assets
out.json
/.idea
priv_*

139
Cargo.lock generated
View File

@ -72,6 +72,12 @@ dependencies = [
"libc",
]
[[package]]
name = "anyhow"
version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6"
[[package]]
name = "async-stream"
version = "0.3.3"
@ -95,9 +101,9 @@ dependencies = [
[[package]]
name = "async-trait"
version = "0.1.58"
version = "0.1.59"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e805d94e6b5001b651426cf4cd446b1ab5f319d27bab5c644f61de0a804360c"
checksum = "31e6e93155431f3931513b243d371981bb2770112b370c82745a1d19d2f99364"
dependencies = [
"proc-macro2",
"quote",
@ -252,7 +258,7 @@ dependencies = [
"num-integer",
"num-traits",
"serde",
"time 0.1.44",
"time 0.1.45",
"wasm-bindgen",
"winapi",
]
@ -281,9 +287,9 @@ dependencies = [
[[package]]
name = "chrono-tz"
version = "0.8.0"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a87b30366b6766751277791b473b674f3bf7fb75696841c784a3eb7e7fbf44ee"
checksum = "fa48fa079165080f11d7753fd0bc175b7d391f276b965fe4b55bfad67856e463"
dependencies = [
"chrono",
"chrono-tz-build 0.1.0",
@ -585,20 +591,10 @@ dependencies = [
"hashbrown",
"lock_api",
"once_cell",
"parking_lot_core 0.9.4",
"parking_lot_core 0.9.5",
"serde",
]
[[package]]
name = "date_time_parser"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f86cad3e692d9b556cb8b64357f50f3b1b8411f3c8999f0bb94523991b5ded6c"
dependencies = [
"chrono",
"regex",
]
[[package]]
name = "date_time_parser"
version = "0.2.0"
@ -736,13 +732,12 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0"
[[package]]
name = "event_parser"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e841f083fbbc766c13ceee32aa64908fa95d9cee7ae6eb6d0888d7479659a61"
source = "git+https://github.com/allquixotic/event-parser?branch=icalendar-bump#72136d84d0caccc2a4497b629ce4cb1d320edfca"
dependencies = [
"chrono",
"date_time_parser 0.1.1",
"icalendar 0.10.0",
"iso8601 0.4.2",
"date_time_parser",
"icalendar",
"iso8601",
"regex",
]
@ -783,9 +778,9 @@ dependencies = [
[[package]]
name = "flate2"
version = "1.0.24"
version = "1.0.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6"
checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841"
dependencies = [
"crc32fast",
"miniz_oxide",
@ -1192,16 +1187,6 @@ dependencies = [
"cxx-build",
]
[[package]]
name = "icalendar"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9ef924cc883333ecdc23b8c4a677119ec6a2db9ef7748a2ae74e77c91ef14df"
dependencies = [
"chrono",
"uuid 0.8.2",
]
[[package]]
name = "icalendar"
version = "0.14.0"
@ -1209,9 +1194,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ecf9c945f7e0df28c2de85439bde5a369dae88d355db6c69c7e649b65f656c"
dependencies = [
"chrono",
"iso8601 0.5.1",
"iso8601",
"pretty_assertions",
"uuid 1.2.2",
"uuid",
]
[[package]]
@ -1309,15 +1294,6 @@ version = "2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f88c5561171189e69df9d98bcf18fd5f9558300f7ea7b801eb8a0fd748bd8745"
[[package]]
name = "iso8601"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5b94fbeb759754d87e1daea745bc8efd3037cd16980331fe1d1524c9a79ce96"
dependencies = [
"nom",
]
[[package]]
name = "iso8601"
version = "0.5.1"
@ -1509,9 +1485,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
version = "0.5.4"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34"
checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa"
dependencies = [
"adler",
]
@ -1716,9 +1692,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "openssl"
version = "0.10.42"
version = "0.10.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13"
checksum = "020433887e44c27ff16365eaa2d380547a94544ad509aff6eb5b6e3e0b27b376"
dependencies = [
"bitflags",
"cfg-if",
@ -1748,9 +1724,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-sys"
version = "0.9.77"
version = "0.9.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b03b84c3b2d099b81f0953422b4d4ad58761589d0229b5506356afca05a3670a"
checksum = "07d5c8cb6e57b3a3612064d7b18b117912b4ce70955c2504d4b741c9e244b132"
dependencies = [
"autocfg",
"cc",
@ -1801,7 +1777,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
dependencies = [
"lock_api",
"parking_lot_core 0.9.4",
"parking_lot_core 0.9.5",
]
[[package]]
@ -1820,9 +1796,9 @@ dependencies = [
[[package]]
name = "parking_lot_core"
version = "0.9.4"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0"
checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba"
dependencies = [
"cfg-if",
"libc",
@ -1886,9 +1862,9 @@ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
[[package]]
name = "pest"
version = "2.4.1"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a528564cc62c19a7acac4d81e01f39e53e25e17b934878f4c6d25cc2836e62f8"
checksum = "5f400b0f7905bf702f9f3dc3df5a121b16c54e9e8012c082905fdf09a931861a"
dependencies = [
"thiserror",
"ucd-trie",
@ -1896,9 +1872,9 @@ dependencies = [
[[package]]
name = "pest_derive"
version = "2.4.1"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5fd9bc6500181952d34bd0b2b0163a54d794227b498be0b7afa7698d0a7b18f"
checksum = "423c2ba011d6e27b02b482a3707c773d19aec65cc024637aec44e19652e66f63"
dependencies = [
"pest",
"pest_generator",
@ -1906,9 +1882,9 @@ dependencies = [
[[package]]
name = "pest_generator"
version = "2.4.1"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2610d5ac5156217b4ff8e46ddcef7cdf44b273da2ac5bca2ecbfa86a330e7c4"
checksum = "3e64e6c2c85031c02fdbd9e5c72845445ca0a724d419aa0bc068ac620c9935c1"
dependencies = [
"pest",
"pest_meta",
@ -1919,9 +1895,9 @@ dependencies = [
[[package]]
name = "pest_meta"
version = "2.4.1"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "824749bf7e21dd66b36fbe26b3f45c713879cccd4a009a917ab8e045ca8246fe"
checksum = "57959b91f0a133f89a68be874a5c88ed689c19cd729ecdb5d762ebf16c64d662"
dependencies = [
"once_cell",
"pest",
@ -2243,16 +2219,16 @@ checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
[[package]]
name = "reminder_rs"
version = "1.6.9"
version = "1.6.10"
dependencies = [
"anyhow",
"base64",
"chrono",
"chrono-tz 0.8.0",
"date_time_parser 0.2.0",
"chrono-tz 0.8.1",
"dotenv",
"env_logger",
"event_parser",
"icalendar 0.14.0",
"icalendar",
"lazy-regex",
"lazy_static",
"levenshtein",
@ -2601,9 +2577,9 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.147"
version = "1.0.148"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965"
checksum = "e53f64bb4ba0191d6d0676e1b141ca55047d83b74f5607e6d8eb88126c52c2dc"
dependencies = [
"serde_derive",
]
@ -2620,9 +2596,9 @@ dependencies = [
[[package]]
name = "serde_derive"
version = "1.0.147"
version = "1.0.148"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852"
checksum = "a55492425aa53521babf6137309e7d34c20bbfbbfcfe2c7f3a047fd1f6b92c0c"
dependencies = [
"proc-macro2",
"quote",
@ -2706,9 +2682,9 @@ dependencies = [
[[package]]
name = "sha-1"
version = "0.10.0"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f"
checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c"
dependencies = [
"cfg-if",
"cpufeatures",
@ -2964,9 +2940,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
[[package]]
name = "syn"
version = "1.0.103"
version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d"
checksum = "4ae548ec36cf198c0ef7710d3c230987c2d6d7bd98ad6edc0274462724c585ce"
dependencies = [
"proc-macro2",
"quote",
@ -3049,9 +3025,9 @@ dependencies = [
[[package]]
name = "time"
version = "0.1.44"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
@ -3122,9 +3098,9 @@ dependencies = [
[[package]]
name = "tokio-macros"
version = "1.8.0"
version = "1.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484"
checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8"
dependencies = [
"proc-macro2",
"quote",
@ -3457,15 +3433,6 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
[[package]]
name = "uuid"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
dependencies = [
"getrandom 0.2.8",
]
[[package]]
name = "uuid"
version = "1.2.2"

View File

@ -1,6 +1,6 @@
[package]
name = "reminder_rs"
version = "1.6.9"
version = "1.6.10"
authors = ["jellywx <judesouthworth@pm.me>"]
edition = "2021"
@ -25,9 +25,10 @@ rand = "0.8"
levenshtein = "1.0"
sqlx = { version = "0.6", features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal", "chrono"]}
base64 = "0.13"
date_time_parser = "0"
event_parser = "0"
event_parser = { git = "https://github.com/allquixotic/event-parser", branch = "icalendar-bump" }
icalendar = "0.14.0"
anyhow = "1"
[dependencies.postman]

View File

@ -1,5 +1,6 @@
CREATE DATABASE IF NOT EXISTS reminders;
SET SQL_MODE='ALLOW_INVALID_DATES';
SET FOREIGN_KEY_CHECKS=0;
USE reminders;
@ -128,7 +129,7 @@ CREATE TABLE reminders.reminders (
`time` INT UNSIGNED DEFAULT 0 NOT NULL,
`interval` INT UNSIGNED DEFAULT NULL,
expires TIMESTAMP DEFAULT NULL,
expires TIMESTAMP NULL DEFAULT NULL,
enabled BOOLEAN DEFAULT 1 NOT NULL,

View File

@ -47,6 +47,5 @@ lazy_static! {
pub static ref THEME_COLOR: u32 = env::var("THEME_COLOR")
.map_or(THEME_COLOR_FALLBACK, |inner| u32::from_str_radix(&inner, 16)
.unwrap_or(THEME_COLOR_FALLBACK));
pub static ref PYTHON_LOCATION: String =
env::var("PYTHON_LOCATION").unwrap_or_else(|_| "venv/bin/python3".to_string());
}

View File

@ -76,7 +76,7 @@ impl ReminderBuilder {
match queried_time.utc_time {
Some(utc_time) => {
if utc_time < (Utc::now() - Duration::seconds(60)).naive_local() {
if NaiveDateTime::from_timestamp_opt(utc_time.parse::<i64>().unwrap_or_default(), 0).unwrap_or_default() < (Utc::now() - Duration::seconds(60)).naive_local() {
Err(ReminderError::PastTime)
} else {
sqlx::query!(

View File

@ -6,9 +6,8 @@ use std::{
use chrono::{DateTime, Datelike, Timelike, Utc};
use chrono_tz::Tz;
use event_parser::*;
use icalendar::Component;
use icalendar::Event;
use event_parser::to_event;
use icalendar::*;
#[derive(Debug)]
pub enum InvalidTime {
@ -200,12 +199,9 @@ impl TimeParser {
}
}
pub async fn natural_parser(time: &str, timezone: &str) -> Option<i64> {
let ts = to_event(time).get_timestamp();
if ts.is_none() {
return None;
pub async fn natural_parser(time: &str, _timezone: &str) -> Option<i64> {
match to_event(time).get_timestamp() {
None => None,
Some(x) => Some(x.timestamp())
}
return Some(ts.unwrap().timestamp());
}