modularization

This commit is contained in:
delorean 2024-05-23 17:30:00 -05:00
parent 072f882490
commit cd6e57f15b
5 changed files with 33 additions and 15 deletions

View File

@ -26,18 +26,20 @@ pub fn parsetitle(s: String) -> String {
} }
out.push_str(w); out.push_str(w);
}); });
out
format!("{}{}{}",
"[".bright_black().bold(),
out.bright_cyan().bold(),
"]".bright_black().bold()
)
} }
pub fn parsehit(sc: u16, url: String, title: String) -> String { pub fn parsehit(sc: u16, url: String) -> String {
format!( format!(
"{} {} {} {}{}{}", "{} {} {}",
fmtcode(sc), fmtcode(sc),
"|".bright_black().bold(), "|".bright_black().bold(),
url.white().underline(), url.white().underline(),
"[".bright_black().bold(),
parsetitle(title).bright_cyan().bold(),
"]".bright_black().bold()
) )
} }

View File

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

View File

@ -2,3 +2,4 @@ pub mod conf;
pub mod console; pub mod console;
pub mod exec; pub mod exec;
pub mod net; pub mod net;
pub mod modules;

15
src/common/modules.rs Normal file
View File

@ -0,0 +1,15 @@
use select::{document::Document, predicate::Name};
use super::console::parsetitle;
pub fn get_title(body: &String) -> String {
let document = Document::from(body.as_str());
let title = document
.find(Name("title"))
.next()
.map(|n| n.text())
.unwrap_or_else(|| "".to_string());
parsetitle(title)
}

View File

@ -1,8 +1,8 @@
use reqwest::{redirect::Policy, Client}; use reqwest::{redirect::Policy, Client};
use select::{document::Document, predicate::Name};
use std::time::Duration; use std::time::Duration;
use super::console::parsehit; use super::console::{parsehit, parsetitle};
use super::modules::*;
pub fn mkclient(redir: bool) -> Result<Client, reqwest::Error> { pub fn mkclient(redir: bool) -> Result<Client, reqwest::Error> {
let rpolicy: Policy = if redir { let rpolicy: Policy = if redir {
@ -29,6 +29,7 @@ pub async fn query(
url: &str, url: &str,
codes: Vec<u16>, codes: Vec<u16>,
exclude: bool, exclude: bool,
titles: bool,
) -> Result<(), reqwest::Error> { ) -> Result<(), reqwest::Error> {
let response: reqwest::Response; let response: reqwest::Response;
if let Ok(res) = sendreq(&c, true, url).await { if let Ok(res) = sendreq(&c, true, url).await {
@ -53,15 +54,13 @@ pub async fn query(
let url: String = response.url().to_string(); let url: String = response.url().to_string();
let body = response.text().await?; let body = response.text().await?;
let document = Document::from(body.as_str()); let mut out = parsehit(sc, url);
let title = document if titles {
.find(Name("title")) out = format!("{} {}", out, get_title(&body));
.next() }
.map(|n| n.text())
.unwrap_or_else(|| "".to_string());
println!("{}", parsehit(sc, url, title)); println!("{}", out);
Ok(()) Ok(())
} }