45 lines
1.2 KiB
Rust
45 lines
1.2 KiB
Rust
use unhtml::FromHtml;
|
|
use unhtml_derive::FromHtml;
|
|
|
|
use crate::context::Context;
|
|
use crate::probe::Probe;
|
|
|
|
#[derive(Debug, FromHtml)]
|
|
#[html(selector = "[itemtype='//data-vocabulary.org/Review-aggregate']")]
|
|
struct Info {
|
|
#[html(selector = "p", attr = "inner")]
|
|
message: String,
|
|
}
|
|
|
|
// http://www.telefonforsaljare.nu/telefonnummer/{}/
|
|
pub struct Telefonforsaljare;
|
|
|
|
impl Probe for Telefonforsaljare {
|
|
fn search(&mut self, ctx: &mut Context, number: &str) -> Result<(), ()> {
|
|
let body = if let Some(cache) = ctx.cache_get("telefonforsaljare", &number) {
|
|
String::from_utf8(cache.data).unwrap()
|
|
} else {
|
|
reqwest::get(&format!(
|
|
"http://www.telefonforsaljare.nu/telefonnummer/{}/",
|
|
number
|
|
))
|
|
.unwrap()
|
|
.text()
|
|
.unwrap()
|
|
};
|
|
|
|
ctx.cache_set("telefonforsaljare", &number, body.as_bytes())
|
|
.expect("wut?! why not?!");
|
|
|
|
println!("telefonforsaljare.nu:");
|
|
|
|
if let Ok(info) = Info::from_html(&body) {
|
|
println!(" {}", info.message);
|
|
} else {
|
|
println!(" Failed to find any data");
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
}
|