aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNerdyPepper <[email protected]>2019-02-06 09:30:40 +0000
committerNerdyPepper <[email protected]>2019-02-06 09:30:40 +0000
commitcf5fae32182d1f5a978034678d0d9d25144577d7 (patch)
treeab21bd384b9e3d2602ca2453f7d64b732e81f158 /src
parentfcc4f66a3786a18563c4ae090d7620c5476a5f86 (diff)
basic logging, try out new library
Diffstat (limited to 'src')
-rw-r--r--src/content.rs38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/content.rs b/src/content.rs
index ed1d8c5..90fd936 100644
--- a/src/content.rs
+++ b/src/content.rs
@@ -2,7 +2,7 @@ extern crate cursive;
2extern crate regex; 2extern crate regex;
3extern crate reqwest; 3extern crate reqwest;
4extern crate serde_json; 4extern crate serde_json;
5extern crate urlencoding; 5extern crate url;
6 6
7use self::regex::Regex; 7use self::regex::Regex;
8use cursive::theme::Effect; 8use cursive::theme::Effect;
@@ -13,32 +13,48 @@ use reqwest::Url;
13use serde_json::Value; 13use serde_json::Value;
14use CONFIGURATION; 14use CONFIGURATION;
15 15
16use content::url::percent_encoding::{ utf8_percent_encode, DEFAULT_ENCODE_SET };
17
18use std::fs::File;
19use std::io::prelude::*;
20
16pub fn query_url_gen(title: &str) -> Url { 21pub fn query_url_gen(title: &str) -> Url {
17 Url::parse_with_params( 22 let url = Url::parse_with_params(
18 &(CONFIGURATION.wiki_url.clone() + "/w/api.php"), 23 &(CONFIGURATION.wiki_url.clone() + "/w/api.php"),
19 &[ 24 &[
20 ("action", "query"), 25 ("action", "query"),
21 ("format", "json"), 26 ("format", "json"),
22 ("prop", "extracts|links"), 27 ("prop", "extracts|links"),
23 ("indexpageids", "1"), 28 ("indexpageids", "1"),
24 ("titles", &urlencoding::encode(&title.replace(" ", "_"))), 29 ("titles", &utf8_percent_encode(&title.replace(" ", "_"), DEFAULT_ENCODE_SET).to_string()[..]),
25 ("redirects", "1"), 30 ("redirects", "1"),
26 ("pllimit", "100"), 31 ("pllimit", "100"),
27 ("explaintext", "1"), 32 ("explaintext", "1"),
28 ], 33 ],
29 ).unwrap() 34 ).unwrap();
35
36 let mut f = File::open("~/.taizen_logs").unwrap();
37 f.write_all(url.as_str().as_bytes()).unwrap();
38
39 return url;
30} 40}
31 41
32pub fn search_url_gen(search: &str) -> Url { 42pub fn search_url_gen(search: &str) -> Url {
33 Url::parse_with_params( 43 let url = Url::parse_with_params(
34 &(CONFIGURATION.wiki_url.clone() + "/w/api.php"), 44 &(CONFIGURATION.wiki_url.clone() + "/w/api.php"),
35 &[ 45 &[
36 ("action", "opensearch"), 46 ("action", "opensearch"),
37 ("format", "json"), 47 ("format", "json"),
38 ("search", &urlencoding::encode(search)), 48 ("search", &utf8_percent_encode(&search, DEFAULT_ENCODE_SET).to_string()[..]),
39 ("limit", "20"), 49 ("limit", "20"),
40 ], 50 ],
41 ).unwrap() 51 ).unwrap();
52
53 let mut f = File::create("taizen_logs.txt").unwrap();
54 f.write_all(url.as_str().as_bytes()).expect("failed to write unicode");
55 f.write_all(search.as_bytes()).unwrap();
56
57 return url;
42} 58}
43 59
44pub fn get_extract(v: &Value) -> Result<String, reqwest::Error> { 60pub fn get_extract(v: &Value) -> Result<String, reqwest::Error> {
@@ -104,8 +120,14 @@ pub fn get_search_results(search: &str) -> Result<Vec<String>, reqwest::Error> {
104 for item in v[1].as_array().unwrap() { 120 for item in v[1].as_array().unwrap() {
105 if let Value::String(x) = item { 121 if let Value::String(x) = item {
106 results.push(x.to_string()) 122 results.push(x.to_string())
107 } 123 };
108 } 124 }
125
126 // let mut f = File::open("taizen_logs.txt").unwrap();
127 // for result in &results {
128 // f.write_all(result.as_bytes()).unwrap();
129 // }
130
109 Ok(results) 131 Ok(results)
110} 132}
111 133