Add: automatically calculate the time 24 hours ago

This commit is contained in:
DuckDuckWhale 2020-11-15 01:29:44 -08:00
parent 7480d79603
commit 6b4f302a4f
3 changed files with 67 additions and 3 deletions

60
Cargo.lock generated
View File

@ -1,5 +1,11 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
[[package]]
name = "autocfg"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]] [[package]]
name = "base-x" name = "base-x"
version = "0.2.8" version = "0.2.8"
@ -36,6 +42,19 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "chrono"
version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"libc",
"num-integer",
"num-traits",
"time 0.1.44",
"winapi",
]
[[package]] [[package]]
name = "chunked_transfer" name = "chunked_transfer"
version = "1.3.0" version = "1.3.0"
@ -55,7 +74,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "784ad0fbab4f3e9cef09f20e0aea6000ae08d2cb98ac4c0abc53df18803d702f" checksum = "784ad0fbab4f3e9cef09f20e0aea6000ae08d2cb98ac4c0abc53df18803d702f"
dependencies = [ dependencies = [
"percent-encoding", "percent-encoding",
"time", "time 0.2.22",
"version_check", "version_check",
] ]
@ -71,7 +90,7 @@ dependencies = [
"publicsuffix", "publicsuffix",
"serde", "serde",
"serde_json", "serde_json",
"time", "time 0.2.22",
"url", "url",
] ]
@ -104,6 +123,7 @@ dependencies = [
name = "gitea-timings" name = "gitea-timings"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"chrono",
"serde", "serde",
"unicode-width", "unicode-width",
"ureq", "ureq",
@ -162,6 +182,25 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
[[package]]
name = "num-integer"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.5.2" version = "1.5.2"
@ -415,6 +454,17 @@ dependencies = [
"unicode-xid", "unicode-xid",
] ]
[[package]]
name = "time"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
"libc",
"wasi",
"winapi",
]
[[package]] [[package]]
name = "time" name = "time"
version = "0.2.22" version = "0.2.22"
@ -543,6 +593,12 @@ version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.68" version = "0.2.68"

View File

@ -5,6 +5,7 @@ authors = ["DuckDuckWhale"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
chrono = "0.4.19"
serde = "1.0.117" serde = "1.0.117"
unicode-width = "0.1.8" unicode-width = "0.1.8"
ureq = { version = "1.5.2", features = ["json"] } ureq = { version = "1.5.2", features = ["json"] }

View File

@ -1,6 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::fs; use std::fs;
use chrono::{Duration as OldDuration, SecondsFormat, Utc};
use serde::Deserialize; use serde::Deserialize;
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
@ -19,8 +20,14 @@ struct Issue {
fn main() { fn main() {
let token = fs::read_to_string("time-tracker-token") let token = fs::read_to_string("time-tracker-token")
.expect("Failed to read token from `time-tracker-token`."); .expect("Failed to read token from `time-tracker-token`.");
let since = Utc::now()
.checked_sub_signed(OldDuration::hours(24))
.expect("Overflowed while trying to subtract 24 hours from now.");
let response = ureq::get("https://git.duckduckwhale.com/api/v1/user/times") let response = ureq::get("https://git.duckduckwhale.com/api/v1/user/times")
.query("since", "2020-11-12T01:18:22-08:00") .query(
"since",
since.to_rfc3339_opts(SecondsFormat::Secs, true).as_ref(),
)
.set("Authorization", format!("token {}", token).as_ref()) .set("Authorization", format!("token {}", token).as_ref())
.timeout_connect(10_000) .timeout_connect(10_000)
.call(); .call();