From 6f84a1ef0be7cc3b3272d5916810213038f3d875 Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Mon, 16 Jul 2018 20:44:53 +0530 Subject: Only 1 request per article --- src/main.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index e604b40..1688ddc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,8 @@ use cursive::views::{ DummyView }; +use serde_json::Value; + pub mod content; use content::*; @@ -23,6 +25,7 @@ fn main() { // set theme main.set_theme(theme_gen()); + main.add_global_callback('q', |s| s.quit()); main.add_global_callback('s', |s| search(s)); @@ -74,14 +77,17 @@ fn on_submit(s: &mut Cursive, name: &String) { let mut extract = String::new(); let mut link_vec: Vec = vec![]; - // handle errors if any - let res = reqwest::get(&url).unwrap(); - match get_extract(res) { + let mut res = reqwest::get(&url).unwrap(); + let v: Value = match serde_json::from_str(&res.text().unwrap()) { + Ok(x) => x, + Err(x) => panic!("Failed to parse json\nReceived error {}", x), + }; + + match get_extract(&v) { Ok(x) => extract = x, Err(e) => pop_error(s, handler(e)) }; - let res = reqwest::get(&url).unwrap(); - match get_links(res) { + match get_links(&v) { Ok(x) => link_vec = x, Err(e) => pop_error(s, handler(e)) }; -- cgit v1.2.3