aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNerdyPepper <[email protected]>2018-07-08 17:40:49 +0100
committerNerdyPepper <[email protected]>2018-07-08 17:40:49 +0100
commite6ed5a9427e21cf6b113cd8edc6d30409e85c2a3 (patch)
treedb1e1a8013c97e6d17e6a0168a678c7fee7f93df /src
parentb57367e72754474d38a08a7aa3e75823971ee4a5 (diff)
Begin work on interwiki links view
Diffstat (limited to 'src')
-rw-r--r--src/content.rs31
1 files changed, 29 insertions, 2 deletions
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 {
43 43
44} 44}
45 45
46pub fn get_extract(mut res: Response) -> Result<String, reqwest::Error> { 46pub fn get_extract(res: &mut Response) -> Result<String, reqwest::Error> {
47 let v: Value = match serde_json::from_str(&res.text()?) { 47 let v: Value = match serde_json::from_str(&res.text()?) {
48 Ok(x) => x, 48 Ok(x) => x,
49 Err(x) => panic!("Failed to parse json\nReceived error {}", x), 49 Err(x) => panic!("Failed to parse json\nReceived error {}", x),
@@ -62,7 +62,7 @@ pub fn get_extract(mut res: Response) -> Result<String, reqwest::Error> {
62 Ok(format!("{}", extract)) 62 Ok(format!("{}", extract))
63 } 63 }
64 // ignore non strings 64 // ignore non strings
65 _ => Ok(format!("")) 65 _ => Ok(format!("This page has been deleted or moved"))
66 } 66 }
67} 67}
68 68
@@ -121,6 +121,33 @@ pub fn get_search_results(search: &str) -> Result<Vec<String>, reqwest::Error> {
121 Ok(results) 121 Ok(results)
122} 122}
123 123
124pub fn get_links(res: &mut Response) -> Result<Vec<String>, reqwest::Error> {
125 let v: Value = match serde_json::from_str(&res.text()?) {
126 Ok(x) => x,
127 Err(x) => panic!("Failed to parse json\nReceived error {}", x),
128 };
129 let pageid = &v["query"]["pageids"][0];
130 let pageid_str = match pageid {
131 Value::String(id) => id,
132 _ => panic!("wut"),
133 };
134
135 let mut links = vec![];
136 match &v["query"]["pages"][pageid_str]["links"] {
137 Value::Array(arr) => {
138 for item in arr {
139 match item["title"] {
140 Value::String(ref title) => links.push(title.to_string()),
141 _ => links.push(String::from("lol"))
142 }
143 }
144 },
145 _ => links.push(String::from("lol"))
146 };
147
148 Ok(links)
149}
150
124pub fn pop_error(s: &mut Cursive, msg: String) { 151pub fn pop_error(s: &mut Cursive, msg: String) {
125 s.add_layer(Dialog::text(format!("{}", msg)) 152 s.add_layer(Dialog::text(format!("{}", msg))
126 .button("Ok", |s| s.quit())); 153 .button("Ok", |s| s.quit()));