Move code around.
This commit is contained in:
72
src/main.rs
72
src/main.rs
@@ -1,68 +1,10 @@
|
||||
use std::env;
|
||||
|
||||
use directories::ProjectDirs;
|
||||
use scraper::{Html, Selector};
|
||||
|
||||
trait Probe {
|
||||
fn search(&mut self, _: &str);
|
||||
}
|
||||
mod probe;
|
||||
|
||||
// https://www.hitta.se/vem-ringde/{}
|
||||
struct Hitta;
|
||||
|
||||
impl Probe for Hitta {
|
||||
fn search(&mut self, number: &str) {
|
||||
let body = reqwest::get(&format!("https://www.hitta.se/vem-ringde/{}", number))
|
||||
.unwrap()
|
||||
.text()
|
||||
.unwrap();
|
||||
|
||||
let document = Html::parse_document(&body);
|
||||
|
||||
let selector = Selector::parse(r#"div[class^="Header__WhoCalledHeader"] > h1"#).unwrap();
|
||||
|
||||
print!("Hitta.se:");
|
||||
|
||||
for element in document.select(&selector) {
|
||||
println!(" {}", element.text().collect::<String>());
|
||||
}
|
||||
|
||||
// Comments.
|
||||
let selector = Selector::parse(r#".topComment--comment"#).unwrap();
|
||||
|
||||
for element in document.select(&selector) {
|
||||
println!(" * {}", element.text().collect::<String>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://gulasidorna.eniro.se/hitta:{}
|
||||
struct Eniro;
|
||||
|
||||
impl Probe for Eniro {
|
||||
fn search(&mut self, _: &str) {}
|
||||
}
|
||||
|
||||
// http://vemringde.se/?q={}
|
||||
struct VemRingde;
|
||||
|
||||
impl Probe for VemRingde {
|
||||
fn search(&mut self, _: &str) {}
|
||||
}
|
||||
|
||||
// http://www.telefonforsaljare.nu/telefonnummer/{}/
|
||||
struct Telefonforsaljare;
|
||||
|
||||
impl Probe for Telefonforsaljare {
|
||||
fn search(&mut self, _: &str) {}
|
||||
}
|
||||
|
||||
// http://konsumentinfo.se/telefonnummer/sverige/{}
|
||||
struct KonsumentInfo;
|
||||
|
||||
impl Probe for KonsumentInfo {
|
||||
fn search(&mut self, _: &str) {}
|
||||
}
|
||||
use crate::probe::*;
|
||||
|
||||
struct Context {
|
||||
dirs: ProjectDirs,
|
||||
@@ -79,9 +21,7 @@ impl Context {
|
||||
None
|
||||
}
|
||||
|
||||
fn cache_set(&mut self, key: &str) {
|
||||
|
||||
}
|
||||
fn cache_set(&mut self, key: &str) {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -96,11 +36,11 @@ fn main() {
|
||||
.expect("must specify a number to search for");
|
||||
|
||||
let mut probes: Vec<Box<Probe>> = vec![
|
||||
Box::new(Hitta),
|
||||
Box::new(Eniro),
|
||||
Box::new(VemRingde),
|
||||
Box::new(Telefonforsaljare),
|
||||
Box::new(Hitta),
|
||||
Box::new(KonsumentInfo),
|
||||
Box::new(Telefonforsaljare),
|
||||
Box::new(VemRingde),
|
||||
];
|
||||
|
||||
for probe in &mut probes {
|
||||
|
||||
15
src/probe.rs
Normal file
15
src/probe.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
mod eniro;
|
||||
mod hitta;
|
||||
mod konsument_info;
|
||||
mod telefonforsaljare;
|
||||
mod vem_ringde;
|
||||
|
||||
pub use self::eniro::Eniro;
|
||||
pub use self::hitta::Hitta;
|
||||
pub use self::konsument_info::KonsumentInfo;
|
||||
pub use self::telefonforsaljare::Telefonforsaljare;
|
||||
pub use self::vem_ringde::VemRingde;
|
||||
|
||||
pub trait Probe {
|
||||
fn search(&mut self, _: &str);
|
||||
}
|
||||
10
src/probe/eniro.rs
Normal file
10
src/probe/eniro.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use scraper::{Html, Selector};
|
||||
|
||||
use crate::probe::Probe;
|
||||
|
||||
// https://gulasidorna.eniro.se/hitta:{}
|
||||
pub struct Eniro;
|
||||
|
||||
impl Probe for Eniro {
|
||||
fn search(&mut self, _: &str) {}
|
||||
}
|
||||
32
src/probe/hitta.rs
Normal file
32
src/probe/hitta.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use scraper::{Html, Selector};
|
||||
|
||||
use crate::probe::Probe;
|
||||
|
||||
// https://www.hitta.se/vem-ringde/{}
|
||||
pub struct Hitta;
|
||||
|
||||
impl Probe for Hitta {
|
||||
fn search(&mut self, number: &str) {
|
||||
let body = reqwest::get(&format!("https://www.hitta.se/vem-ringde/{}", number))
|
||||
.unwrap()
|
||||
.text()
|
||||
.unwrap();
|
||||
|
||||
let document = Html::parse_document(&body);
|
||||
|
||||
let selector = Selector::parse(r#"div[class^="Header__WhoCalledHeader"] > h1"#).unwrap();
|
||||
|
||||
print!("Hitta.se:");
|
||||
|
||||
for element in document.select(&selector) {
|
||||
println!(" {}", element.text().collect::<String>());
|
||||
}
|
||||
|
||||
// Comments.
|
||||
let selector = Selector::parse(r#".topComment--comment"#).unwrap();
|
||||
|
||||
for element in document.select(&selector) {
|
||||
println!(" * {}", element.text().collect::<String>());
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src/probe/konsument_info.rs
Normal file
10
src/probe/konsument_info.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use scraper::{Html, Selector};
|
||||
|
||||
use crate::probe::Probe;
|
||||
|
||||
// http://konsumentinfo.se/telefonnummer/sverige/{}
|
||||
pub struct KonsumentInfo;
|
||||
|
||||
impl Probe for KonsumentInfo {
|
||||
fn search(&mut self, _: &str) {}
|
||||
}
|
||||
10
src/probe/telefonforsaljare.rs
Normal file
10
src/probe/telefonforsaljare.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use scraper::{Html, Selector};
|
||||
|
||||
use crate::probe::Probe;
|
||||
|
||||
// http://www.telefonforsaljare.nu/telefonnummer/{}/
|
||||
pub struct Telefonforsaljare;
|
||||
|
||||
impl Probe for Telefonforsaljare {
|
||||
fn search(&mut self, _: &str) {}
|
||||
}
|
||||
10
src/probe/vem_ringde.rs
Normal file
10
src/probe/vem_ringde.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use scraper::{Html, Selector};
|
||||
|
||||
use crate::probe::Probe;
|
||||
|
||||
// http://vemringde.se/?q={}
|
||||
pub struct VemRingde;
|
||||
|
||||
impl Probe for VemRingde {
|
||||
fn search(&mut self, _: &str) {}
|
||||
}
|
||||
Reference in New Issue
Block a user