40 lines
1020 B
Rust
40 lines
1020 B
Rust
use unhtml::FromHtml;
|
|
use unhtml_derive::FromHtml;
|
|
|
|
use crate::context::Context;
|
|
use crate::probe::Probe;
|
|
|
|
#[derive(Debug, FromHtml)]
|
|
#[html(selector = ".error-box")]
|
|
struct Error {
|
|
#[html(selector = "h2", attr = "inner")]
|
|
message: String,
|
|
}
|
|
|
|
// https://gulasidorna.eniro.se/hitta:{}
|
|
pub struct Eniro;
|
|
|
|
impl Probe for Eniro {
|
|
fn search(&mut self, ctx: &mut Context, number: &str) {
|
|
let body = if let Some(cache) = ctx.cache_get("eniro", &number) {
|
|
String::from_utf8(cache.data).unwrap()
|
|
} else {
|
|
reqwest::get(&format!("https://gulasidorna.eniro.se/hitta:{}", number))
|
|
.unwrap()
|
|
.text()
|
|
.unwrap()
|
|
};
|
|
|
|
ctx.cache_set("eniro", &number, body.as_bytes())
|
|
.expect("wut?! why not?!");
|
|
|
|
println!("eniro.se:");
|
|
|
|
if let Ok(error) = Error::from_html(&body) {
|
|
println!(" {}", error.message);
|
|
} else {
|
|
println!(" Failed to find any data");
|
|
}
|
|
}
|
|
}
|