diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/src/main.rs b/src/main.rs index 951c94c..1573cdb 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -3,33 +3,21 @@ extern crate serde_json; | |||
3 | 3 | ||
4 | use serde_json::Value; | 4 | use serde_json::Value; |
5 | 5 | ||
6 | fn main() { | 6 | pub mod content; |
7 | println!("{}", get_extract("scale")); | ||
8 | } | ||
9 | 7 | ||
10 | fn get_extract(title: &str) -> String { | 8 | fn main() { |
11 | let url = format!("https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&list=&meta=&indexpageids=1&continue=%7C%7Cimageinfo&titles={}&exlimit=20&explaintext=1&exsectionformat=plain", title); | 9 | let url = format!("https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&list=&meta=&indexpageids=1&continue=%7C%7Cimageinfo&titles={}&exlimit=20&explaintext=1&exsectionformat=plain", title); |
12 | let res = reqwest::get(&url); | 10 | let res = reqwest::get(&url); |
13 | 11 | ||
14 | match res { | 12 | match res { |
15 | Ok(mut res) => { | 13 | Ok(res) => { |
16 | if res.status().is_success() { | 14 | if res.status().is_success() { |
17 | let mut v: Value = serde_json::from_str(&res.text().unwrap()).unwrap(); | 15 | content::get_extract("") |
18 | |||
19 | // Fetch page and pageids of requested title(s) | ||
20 | let pageid = &v["query"]["pageids"][0]; | ||
21 | let pageid_str = match pageid { | ||
22 | Value::String(id) => id, | ||
23 | _ => panic!("wut"), | ||
24 | }; | ||
25 | |||
26 | format!("{:#}", &v["query"]["pages"][pageid_str]["extract"]) | ||
27 | } else { | ||
28 | format!("Error while parsing url.\nRecieved {}", res.status()) | ||
29 | } | 16 | } |
30 | }, | 17 | } |
31 | Err(_) => { | 18 | |
32 | format!("Failed to parse URL") | 19 | Err(_) { |
20 | panic!("Oh no!"); | ||
33 | } | 21 | } |
34 | } | 22 | } |
35 | } | 23 | } |