modularization
This commit is contained in:
parent
072f882490
commit
cd6e57f15b
@ -26,18 +26,20 @@ pub fn parsetitle(s: String) -> String {
|
||||
}
|
||||
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!(
|
||||
"{} {} {} {}{}{}",
|
||||
"{} {} {}",
|
||||
fmtcode(sc),
|
||||
"|".bright_black().bold(),
|
||||
url.white().underline(),
|
||||
"[".bright_black().bold(),
|
||||
parsetitle(title).bright_cyan().bold(),
|
||||
"]".bright_black().bold()
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ pub async fn takeoff(args: Config, params: Params) {
|
||||
.trim(),
|
||||
scodes,
|
||||
params.exclude,
|
||||
args.pulltitles
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
@ -2,3 +2,4 @@ pub mod conf;
|
||||
pub mod console;
|
||||
pub mod exec;
|
||||
pub mod net;
|
||||
pub mod modules;
|
||||
|
15
src/common/modules.rs
Normal file
15
src/common/modules.rs
Normal 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)
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
use reqwest::{redirect::Policy, Client};
|
||||
use select::{document::Document, predicate::Name};
|
||||
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> {
|
||||
let rpolicy: Policy = if redir {
|
||||
@ -29,6 +29,7 @@ pub async fn query(
|
||||
url: &str,
|
||||
codes: Vec<u16>,
|
||||
exclude: bool,
|
||||
titles: bool,
|
||||
) -> Result<(), reqwest::Error> {
|
||||
let response: reqwest::Response;
|
||||
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 body = response.text().await?;
|
||||
|
||||
let document = Document::from(body.as_str());
|
||||
let mut out = parsehit(sc, url);
|
||||
|
||||
let title = document
|
||||
.find(Name("title"))
|
||||
.next()
|
||||
.map(|n| n.text())
|
||||
.unwrap_or_else(|| "".to_string());
|
||||
if titles {
|
||||
out = format!("{} {}", out, get_title(&body));
|
||||
}
|
||||
|
||||
println!("{}", parsehit(sc, url, title));
|
||||
println!("{}", out);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user