From e6ed5a9427e21cf6b113cd8edc6d30409e85c2a3 Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Sun, 8 Jul 2018 22:10:49 +0530 Subject: Begin work on interwiki links view --- src/content.rs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/content.rs b/src/content.rs index 4c71fd0..1c75360 100644 --- a/src/content.rs +++ b/src/content.rs @@ -43,7 +43,7 @@ pub fn search_url_gen(search: &str) -> String { } -pub fn get_extract(mut res: Response) -> Result { +pub fn get_extract(res: &mut Response) -> Result { let v: Value = match serde_json::from_str(&res.text()?) { Ok(x) => x, Err(x) => panic!("Failed to parse json\nReceived error {}", x), @@ -62,7 +62,7 @@ pub fn get_extract(mut res: Response) -> Result { Ok(format!("{}", extract)) } // ignore non strings - _ => Ok(format!("")) + _ => Ok(format!("This page has been deleted or moved")) } } @@ -121,6 +121,33 @@ pub fn get_search_results(search: &str) -> Result, reqwest::Error> { Ok(results) } +pub fn get_links(res: &mut Response) -> Result, reqwest::Error> { + let v: Value = match serde_json::from_str(&res.text()?) { + Ok(x) => x, + Err(x) => panic!("Failed to parse json\nReceived error {}", x), + }; + let pageid = &v["query"]["pageids"][0]; + let pageid_str = match pageid { + Value::String(id) => id, + _ => panic!("wut"), + }; + + let mut links = vec![]; + match &v["query"]["pages"][pageid_str]["links"] { + Value::Array(arr) => { + for item in arr { + match item["title"] { + Value::String(ref title) => links.push(title.to_string()), + _ => links.push(String::from("lol")) + } + } + }, + _ => links.push(String::from("lol")) + }; + + Ok(links) +} + pub fn pop_error(s: &mut Cursive, msg: String) { s.add_layer(Dialog::text(format!("{}", msg)) .button("Ok", |s| s.quit())); -- cgit v1.2.3