aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/content.rs51
-rw-r--r--src/main.rs2
2 files changed, 26 insertions, 27 deletions
diff --git a/src/content.rs b/src/content.rs
index 30d8f22..ed1d8c5 100644
--- a/src/content.rs
+++ b/src/content.rs
@@ -9,37 +9,36 @@ use cursive::theme::Effect;
9use cursive::utils::markup::StyledString; 9use cursive::utils::markup::StyledString;
10use cursive::views::Dialog; 10use cursive::views::Dialog;
11use cursive::Cursive; 11use cursive::Cursive;
12use reqwest::Url;
12use serde_json::Value; 13use serde_json::Value;
13use CONFIGURATION; 14use CONFIGURATION;
14 15
15pub fn query_url_gen(title: &str) -> String { 16pub fn query_url_gen(title: &str) -> Url {
16 // query config 17 Url::parse_with_params(
17 let mut url = CONFIGURATION.wiki_url.clone(); 18 &(CONFIGURATION.wiki_url.clone() + "/w/api.php"),
18 url.push_str("/w/api.php?"); 19 &[
19 url.push_str("action=query&"); 20 ("action", "query"),
20 url.push_str("format=json&"); 21 ("format", "json"),
21 url.push_str("prop=extracts%7Clinks&"); 22 ("prop", "extracts|links"),
22 url.push_str("indexpageids=1&"); 23 ("indexpageids", "1"),
23 url.push_str("titles="); 24 ("titles", &urlencoding::encode(&title.replace(" ", "_"))),
24 url.push_str(&urlencoding::encode(&title.replace(" ", "_"))); 25 ("redirects", "1"),
25 url.push_str("&"); 26 ("pllimit", "100"),
26 url.push_str("redirects=1&"); 27 ("explaintext", "1"),
27 url.push_str("pllimit=100&"); 28 ],
28 url.push_str("explaintext=1"); 29 ).unwrap()
29 url
30} 30}
31 31
32pub fn search_url_gen(search: &str) -> String { 32pub fn search_url_gen(search: &str) -> Url {
33 // search config 33 Url::parse_with_params(
34 let mut url = CONFIGURATION.wiki_url.clone(); 34 &(CONFIGURATION.wiki_url.clone() + "/w/api.php"),
35 url.push_str("/w/api.php?"); 35 &[
36 url.push_str("action=opensearch&"); 36 ("action", "opensearch"),
37 url.push_str("format=json&"); 37 ("format", "json"),
38 url.push_str("search="); 38 ("search", &urlencoding::encode(search)),
39 url.push_str(&urlencoding::encode(&search)); 39 ("limit", "20"),
40 url.push_str("&"); 40 ],
41 url.push_str("limit=20"); 41 ).unwrap()
42 url
43} 42}
44 43
45pub fn get_extract(v: &Value) -> Result<String, reqwest::Error> { 44pub fn get_extract(v: &Value) -> Result<String, reqwest::Error> {
diff --git a/src/main.rs b/src/main.rs
index c6249c4..5057433 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -124,7 +124,7 @@ fn on_submit(s: &mut Cursive, name: &str) {
124 let mut extract = String::new(); 124 let mut extract = String::new();
125 let mut link_vec: Vec<String> = vec![]; 125 let mut link_vec: Vec<String> = vec![];
126 126
127 let mut res = reqwest::get(&url).unwrap(); 127 let mut res = reqwest::get(url).unwrap();
128 let v: Value = res.json().expect("Failed to parse json"); 128 let v: Value = res.json().expect("Failed to parse json");
129 129
130 match get_extract(&v) { 130 match get_extract(&v) {