From d94ca7688ca68e4a5ca3cc77796f91fb814da82e Mon Sep 17 00:00:00 2001 From: delorean Date: Thu, 23 May 2024 20:33:33 -0500 Subject: [PATCH] added optional timestamp support --- Cargo.lock | 71 +++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 3 +- src/common/conf.rs | 4 +++ src/common/console.rs | 10 +++++- src/common/exec.rs | 1 + src/common/net.rs | 7 ++++- 6 files changed, 93 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e2ae705..3e4cb00 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,21 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "0.6.13" @@ -143,6 +158,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets 0.52.5", +] + [[package]] name = "clap" version = "4.5.4" @@ -539,6 +568,29 @@ dependencies = [ "tracing", ] +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "idna" version = "0.5.0" @@ -702,6 +754,15 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -1164,6 +1225,7 @@ dependencies = [ name = "speedboat" version = "0.1.0" dependencies = [ + "chrono", "clap", "colored", "futures", @@ -1540,6 +1602,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index 15f4a80..0a73875 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,9 +6,10 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +chrono = "0.4.38" clap = { version = "4.5.4", features = ["derive"] } colored = "2.1.0" futures = "0.3.30" reqwest = "0.12.4" select = "0.6.0" -tokio = { version = "1", features = ["full"] } +tokio = { version = "1", features = ["full"] } \ No newline at end of file diff --git a/src/common/conf.rs b/src/common/conf.rs index 189ea09..622b96b 100644 --- a/src/common/conf.rs +++ b/src/common/conf.rs @@ -41,6 +41,10 @@ pub struct Config { #[clap(default_value_t = 0, long = "body")] /// read n bytes of the response document body pub bodysize: usize, + + #[clap(long = "ts")] + /// include timestamps of requests + pub timestamps: bool, } pub fn load() -> Config { diff --git a/src/common/console.rs b/src/common/console.rs index 1ecef7e..4ca4f9e 100644 --- a/src/common/console.rs +++ b/src/common/console.rs @@ -1,4 +1,5 @@ use colored::{ColoredString, Colorize}; +use chrono::Local; use std::process; use super::conf::VERSION; @@ -22,7 +23,7 @@ pub fn fmtwhitespace(s: String) -> String { pub fn fmtcode(code: u16) -> ColoredString { match code { - 200..=299 => code.to_string().green(), + 200..=299 => code.to_string().green().bold(), 300..=399 => code.to_string().yellow(), 400..=499 => code.to_string().bright_red(), 500..=599 => code.to_string().red().bold(), @@ -30,6 +31,13 @@ pub fn fmtcode(code: u16) -> ColoredString { } } +pub fn tstamp() -> String { + let date = Local::now(); + + let datestr = format!("{}", date.format("[%Y-%m-%d][%H:%M:%S}")); + format!("{}", datestr.bright_blue()) +} + pub fn parsetitle(s: String) -> String { let title = fmtwhitespace(s); diff --git a/src/common/exec.rs b/src/common/exec.rs index b682ac1..9b08d98 100644 --- a/src/common/exec.rs +++ b/src/common/exec.rs @@ -31,6 +31,7 @@ pub async fn takeoff(args: Config, params: Params) { scodes, params.exclude, args.pulltitles, + args.timestamps, args.bodysize ) .await; diff --git a/src/common/net.rs b/src/common/net.rs index 6c368cf..0949a88 100644 --- a/src/common/net.rs +++ b/src/common/net.rs @@ -1,7 +1,7 @@ use reqwest::{redirect::Policy, Client}; use std::time::Duration; -use super::console::parsehit; +use super::console::{parsehit, tstamp}; use super::modules::*; pub fn mkclient(redir: bool) -> Result { @@ -30,6 +30,7 @@ pub async fn query( codes: Vec, exclude: bool, titles: bool, + timestamps: bool, bodysize: usize, ) -> Result<(), reqwest::Error> { let response: reqwest::Response; @@ -57,6 +58,10 @@ pub async fn query( let mut out = parsehit(sc, url); + if timestamps { + out = format!("{} {}", tstamp(), out); + } + if titles { out = format!("{} {}", out, get_title(&body)); }