Cache works, but needs a lot more work.

This commit is contained in:
2018-12-18 14:42:46 +01:00
parent 9bf1d22876
commit 9f9955a848
10 changed files with 176 additions and 61 deletions

View File

@@ -1,19 +1,28 @@
use scraper::{Html, Selector};
use crate::context::Context;
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();
fn search(&mut self, ctx: &mut Context, number: &str) {
let body = if let Some(cache) = ctx.cache_get("hitta", &number) {
String::from_utf8(cache.data)
.unwrap()
} else {
reqwest::get(&format!("https://www.hitta.se/vem-ringde/{}", number))
.unwrap()
.text()
.unwrap()
};
ctx.cache_set("hitta", &number, body.as_bytes()).expect("wut?! why not?!");
let document = Html::parse_document(&body);
// Header.
let selector = Selector::parse(r#"div[class^="Header__WhoCalledHeader"] > h1"#).unwrap();
print!("Hitta.se:");