Broken use of event_parser (WIP)

This commit is contained in:
Sean McNamara 2022-11-30 07:22:47 -05:00
parent aa74a7f9a3
commit 042456eced
4 changed files with 147 additions and 36 deletions

133
Cargo.lock generated
View File

@ -477,6 +477,16 @@ dependencies = [
"memchr",
]
[[package]]
name = "ctor"
version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096"
dependencies = [
"quote",
"syn",
]
[[package]]
name = "ctr"
version = "0.9.2"
@ -579,6 +589,26 @@ dependencies = [
"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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0521d96e513670773ac503e5f5239178c3aef16cffda1e77a3cdbdbe993fb5a"
dependencies = [
"chrono",
"regex",
]
[[package]]
name = "der"
version = "0.5.1"
@ -640,6 +670,12 @@ dependencies = [
"syn",
]
[[package]]
name = "diff"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
[[package]]
name = "digest"
version = "0.10.6"
@ -697,6 +733,19 @@ version = "2.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0"
[[package]]
name = "event_parser"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e841f083fbbc766c13ceee32aa64908fa95d9cee7ae6eb6d0888d7479659a61"
dependencies = [
"chrono",
"date_time_parser 0.1.1",
"icalendar 0.10.0",
"iso8601 0.4.2",
"regex",
]
[[package]]
name = "fastrand"
version = "1.8.0"
@ -1143,6 +1192,28 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ecf9c945f7e0df28c2de85439bde5a369dae88d355db6c69c7e649b65f656c"
dependencies = [
"chrono",
"iso8601 0.5.1",
"pretty_assertions",
"uuid 1.2.2",
]
[[package]]
name = "ident_case"
version = "1.0.1"
@ -1238,6 +1309,24 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "296af15e112ec6dc38c9fd3ae027b5337a75466e8eed757bd7d5cf742ea85eb6"
dependencies = [
"nom",
]
[[package]]
name = "itertools"
version = "0.10.5"
@ -1679,6 +1768,15 @@ dependencies = [
"num-traits",
]
[[package]]
name = "output_vt100"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66"
dependencies = [
"winapi",
]
[[package]]
name = "overload"
version = "0.1.1"
@ -1974,6 +2072,18 @@ version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "pretty_assertions"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a25e9bcb20aa780fd0bb16b72403a9064d6b3f22f026946029acb941a50af755"
dependencies = [
"ctor",
"diff",
"output_vt100",
"yansi",
]
[[package]]
name = "proc-macro2"
version = "1.0.47"
@ -2133,13 +2243,16 @@ checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
[[package]]
name = "reminder_rs"
version = "1.6.8"
version = "1.6.9"
dependencies = [
"base64",
"chrono",
"chrono-tz 0.8.0",
"date_time_parser 0.2.0",
"dotenv",
"env_logger",
"event_parser",
"icalendar 0.14.0",
"lazy-regex",
"lazy_static",
"levenshtein",
@ -3344,6 +3457,24 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c"
dependencies = [
"getrandom 0.2.8",
]
[[package]]
name = "valuable"
version = "0.1.0"

View File

@ -2,7 +2,7 @@
name = "reminder_rs"
version = "1.6.9"
authors = ["jellywx <judesouthworth@pm.me>"]
edition = "2018"
edition = "2021"
[dependencies]
poise = "0.4"
@ -25,6 +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"
icalendar = "0.14.0"
[dependencies.postman]
path = "postman"

13
dp.py
View File

@ -1,13 +0,0 @@
import dateparser
import sys
import pytz
from datetime import datetime
dt = dateparser.parse(sys.argv[1], settings={
'TIMEZONE': sys.argv[2],
'TO_TIMEZONE': sys.argv[3],
'RELATIVE_BASE': datetime.now(pytz.timezone(sys.argv[2])).replace(tzinfo=None),
'PREFER_DATES_FROM': 'future',
})
sys.stdout.write(str(int(dt.timestamp()) if dt is not None else -1))

View File

@ -1,15 +1,14 @@
use std::{
convert::TryFrom,
fmt::{Display, Formatter, Result as FmtResult},
str::from_utf8,
time::{SystemTime, UNIX_EPOCH},
};
use chrono::{DateTime, Datelike, Timelike, Utc};
use chrono_tz::Tz;
use tokio::process::Command;
use crate::consts::{LOCAL_TIMEZONE, PYTHON_LOCATION};
use event_parser::*;
use icalendar::Component;
use icalendar::Event;
#[derive(Debug)]
pub enum InvalidTime {
@ -202,21 +201,11 @@ impl TimeParser {
}
pub async fn natural_parser(time: &str, timezone: &str) -> Option<i64> {
Command::new(&*PYTHON_LOCATION)
.arg("-c")
.arg(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/dp.py")))
.arg(time)
.arg(timezone)
.arg(&*LOCAL_TIMEZONE)
.output()
.await
.ok()
.and_then(|inner| {
if inner.status.success() {
Some(from_utf8(&*inner.stdout).unwrap().parse::<i64>().unwrap())
} else {
None
let ts = to_event(time).get_timestamp();
if ts.is_none() {
return None;
}
})
.and_then(|inner| if inner < 0 { None } else { Some(inner) })
return Some(ts.unwrap().timestamp());
}