Added some basic logging.
Fix cache invalidation (1 day for now).
This commit is contained in:
@@ -11,25 +11,24 @@ struct Info {
|
||||
message: String,
|
||||
}
|
||||
|
||||
// http://konsumentinfo.se/telefonnummer/sverige/{}
|
||||
pub struct KonsumentInfo;
|
||||
|
||||
impl Probe for KonsumentInfo {
|
||||
fn uri(&self, number: &str) -> String {
|
||||
format!("http://konsumentinfo.se/telefonnummer/sverige/{}", number)
|
||||
}
|
||||
|
||||
fn search(&mut self, ctx: &mut Context, number: &str) -> Result<(), ()> {
|
||||
let body = if let Some(cache) = ctx.cache_get("konsument_info", &number) {
|
||||
String::from_utf8(cache.data).unwrap()
|
||||
} else {
|
||||
reqwest::get(&format!(
|
||||
"http://konsumentinfo.se/telefonnummer/sverige/{}",
|
||||
number
|
||||
))
|
||||
.unwrap()
|
||||
.text()
|
||||
.unwrap()
|
||||
};
|
||||
let body = reqwest::get(&self.uri(number)).unwrap().text().unwrap();
|
||||
|
||||
ctx.cache_set("konsument_info", &number, body.as_bytes())
|
||||
.expect("wut?! why not?!");
|
||||
ctx.cache_set("konsument_info", &number, body.as_bytes())
|
||||
.expect("wut?! why not?!");
|
||||
|
||||
body
|
||||
};
|
||||
|
||||
println!("konsumentinfo.se:");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user