diff options
author | NerdyPepper <[email protected]> | 2018-06-19 05:22:31 +0100 |
---|---|---|
committer | NerdyPepper <[email protected]> | 2018-06-19 05:22:31 +0100 |
commit | 4bf31c45284b869a690d510300aa0a29a572f73c (patch) | |
tree | fe44895585d6257611016a78c375c99331858b13 | |
parent | 07e74a1e49e3b8f9d54512ff6e308dbb48fdeeae (diff) |
Add basic search functionality
-rw-r--r-- | src/content.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/content.rs b/src/content.rs index 67e8d24..17ad40a 100644 --- a/src/content.rs +++ b/src/content.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | pub fn url_gen(title: &str) -> String { | 1 | pub fn query_url_gen(title: &str) -> String { |
2 | 2 | ||
3 | title.replace(" ", "%20"); | 3 | title.replace(" ", "%20"); |
4 | 4 | ||
@@ -8,8 +8,24 @@ pub fn url_gen(title: &str) -> String { | |||
8 | url.push_str("action=query&"); | 8 | url.push_str("action=query&"); |
9 | url.push_str("format=json&"); | 9 | url.push_str("format=json&"); |
10 | url.push_str("prop=extracts&"); | 10 | url.push_str("prop=extracts&"); |
11 | url.push_str(format!("titles={}", title)); | 11 | url.push_str(format!("titles={}&", title)); |
12 | url.push_str("explaintext=1"); | 12 | url.push_str("explaintext=1"); |
13 | |||
14 | url | ||
15 | } | ||
16 | |||
17 | pub fn search_url_gen(search: &str) -> String { | ||
18 | // /w/api.php?action=opensearch&format=json&search=dota%202&limit=5; | ||
19 | |||
20 | search.replace(" ", "%20"); | ||
21 | |||
22 | let url = "https://en.wikipedia.org"; | ||
23 | url.push_str("w/api.php?"); | ||
24 | url.push_str("action=opensearch&"); | ||
25 | url.push_str("format=json&"); | ||
26 | url.push_str(format!("search={}&", search)); | ||
27 | url.push_str("limit=5"); | ||
28 | |||
13 | } | 29 | } |
14 | 30 | ||
15 | pub fn get_extract(title: &str, red: Response) -> String { | 31 | pub fn get_extract(title: &str, red: Response) -> String { |