Added some basic logging.
Fix cache invalidation (1 day for now).
This commit is contained in:
@@ -5,32 +5,34 @@ use crate::context::Context;
|
||||
use crate::probe::Probe;
|
||||
|
||||
#[derive(Debug, FromHtml)]
|
||||
#[html(selector = ".error-box")]
|
||||
#[html(selector = ".PhoneNoHit")]
|
||||
struct Error {
|
||||
#[html(selector = "h2", attr = "inner")]
|
||||
#[html(selector = ".search-info-container > p", attr = "inner")]
|
||||
message: String,
|
||||
}
|
||||
|
||||
// https://gulasidorna.eniro.se/hitta:{}
|
||||
pub struct Eniro;
|
||||
|
||||
impl Probe for Eniro {
|
||||
fn uri(&self, number: &str) -> String {
|
||||
format!("https://gulasidorna.eniro.se/hitta:{}", number)
|
||||
}
|
||||
|
||||
fn search(&mut self, ctx: &mut Context, number: &str) -> Result<(), ()> {
|
||||
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()
|
||||
};
|
||||
let body = reqwest::get(&self.uri(number)).unwrap().text().unwrap();
|
||||
|
||||
ctx.cache_set("eniro", &number, body.as_bytes())
|
||||
.expect("wut?! why not?!");
|
||||
ctx.cache_set("eniro", &number, body.as_bytes())
|
||||
.expect("wut?! why not?!");
|
||||
|
||||
body
|
||||
};
|
||||
|
||||
if let Ok(error) = Error::from_html(&body) {
|
||||
println!("eniro.se:");
|
||||
println!(" {}", error.message);
|
||||
println!(" Antal sökningar på det här numret: {}", error.message);
|
||||
|
||||
Ok(())
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user