added optional timestamp support

This commit is contained in:
delorean 2024-05-23 20:33:33 -05:00
parent d9b0eef4df
commit d94ca7688c
6 changed files with 93 additions and 3 deletions

71
Cargo.lock generated
View File

@ -17,6 +17,21 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" 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]] [[package]]
name = "anstream" name = "anstream"
version = "0.6.13" version = "0.6.13"
@ -143,6 +158,20 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 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]] [[package]]
name = "clap" name = "clap"
version = "4.5.4" version = "4.5.4"
@ -539,6 +568,29 @@ dependencies = [
"tracing", "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]] [[package]]
name = "idna" name = "idna"
version = "0.5.0" version = "0.5.0"
@ -702,6 +754,15 @@ version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" 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]] [[package]]
name = "num_cpus" name = "num_cpus"
version = "1.16.0" version = "1.16.0"
@ -1164,6 +1225,7 @@ dependencies = [
name = "speedboat" name = "speedboat"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"chrono",
"clap", "clap",
"colored", "colored",
"futures", "futures",
@ -1540,6 +1602,15 @@ dependencies = [
"wasm-bindgen", "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]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.48.0" version = "0.48.0"

View File

@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
chrono = "0.4.38"
clap = { version = "4.5.4", features = ["derive"] } clap = { version = "4.5.4", features = ["derive"] }
colored = "2.1.0" colored = "2.1.0"
futures = "0.3.30" futures = "0.3.30"

View File

@ -41,6 +41,10 @@ pub struct Config {
#[clap(default_value_t = 0, long = "body")] #[clap(default_value_t = 0, long = "body")]
/// read n bytes of the response document body /// read n bytes of the response document body
pub bodysize: usize, pub bodysize: usize,
#[clap(long = "ts")]
/// include timestamps of requests
pub timestamps: bool,
} }
pub fn load() -> Config { pub fn load() -> Config {

View File

@ -1,4 +1,5 @@
use colored::{ColoredString, Colorize}; use colored::{ColoredString, Colorize};
use chrono::Local;
use std::process; use std::process;
use super::conf::VERSION; use super::conf::VERSION;
@ -22,7 +23,7 @@ pub fn fmtwhitespace(s: String) -> String {
pub fn fmtcode(code: u16) -> ColoredString { pub fn fmtcode(code: u16) -> ColoredString {
match code { match code {
200..=299 => code.to_string().green(), 200..=299 => code.to_string().green().bold(),
300..=399 => code.to_string().yellow(), 300..=399 => code.to_string().yellow(),
400..=499 => code.to_string().bright_red(), 400..=499 => code.to_string().bright_red(),
500..=599 => code.to_string().red().bold(), 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 { pub fn parsetitle(s: String) -> String {
let title = fmtwhitespace(s); let title = fmtwhitespace(s);

View File

@ -31,6 +31,7 @@ pub async fn takeoff(args: Config, params: Params) {
scodes, scodes,
params.exclude, params.exclude,
args.pulltitles, args.pulltitles,
args.timestamps,
args.bodysize args.bodysize
) )
.await; .await;

View File

@ -1,7 +1,7 @@
use reqwest::{redirect::Policy, Client}; use reqwest::{redirect::Policy, Client};
use std::time::Duration; use std::time::Duration;
use super::console::parsehit; use super::console::{parsehit, tstamp};
use super::modules::*; use super::modules::*;
pub fn mkclient(redir: bool) -> Result<Client, reqwest::Error> { pub fn mkclient(redir: bool) -> Result<Client, reqwest::Error> {
@ -30,6 +30,7 @@ pub async fn query(
codes: Vec<u16>, codes: Vec<u16>,
exclude: bool, exclude: bool,
titles: bool, titles: bool,
timestamps: bool,
bodysize: usize, bodysize: usize,
) -> Result<(), reqwest::Error> { ) -> Result<(), reqwest::Error> {
let response: reqwest::Response; let response: reqwest::Response;
@ -57,6 +58,10 @@ pub async fn query(
let mut out = parsehit(sc, url); let mut out = parsehit(sc, url);
if timestamps {
out = format!("{} {}", tstamp(), out);
}
if titles { if titles {
out = format!("{} {}", out, get_title(&body)); out = format!("{} {}", out, get_title(&body));
} }