aboutsummaryrefslogtreecommitdiff
path: root/src/content.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/content.rs')
-rw-r--r--src/content.rs43
1 files changed, 31 insertions, 12 deletions
diff --git a/src/content.rs b/src/content.rs
index 90fd936..6a06cc5 100644
--- a/src/content.rs
+++ b/src/content.rs
@@ -13,11 +13,13 @@ 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 }; 16use content::url::percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET};
17 17
18use std::fs::File; 18use std::fs::OpenOptions;
19use std::io::prelude::*; 19use std::io::prelude::*;
20 20
21extern crate dirs;
22
21pub fn query_url_gen(title: &str) -> Url { 23pub fn query_url_gen(title: &str) -> Url {
22 let url = Url::parse_with_params( 24 let url = Url::parse_with_params(
23 &(CONFIGURATION.wiki_url.clone() + "/w/api.php"), 25 &(CONFIGURATION.wiki_url.clone() + "/w/api.php"),
@@ -26,15 +28,24 @@ pub fn query_url_gen(title: &str) -> Url {
26 ("format", "json"), 28 ("format", "json"),
27 ("prop", "extracts|links"), 29 ("prop", "extracts|links"),
28 ("indexpageids", "1"), 30 ("indexpageids", "1"),
29 ("titles", &utf8_percent_encode(&title.replace(" ", "_"), DEFAULT_ENCODE_SET).to_string()[..]), 31 (
32 "titles",
33 &utf8_percent_encode(&title.replace(" ", "_"), DEFAULT_ENCODE_SET).to_string()[..],
34 ),
30 ("redirects", "1"), 35 ("redirects", "1"),
31 ("pllimit", "100"), 36 ("pllimit", "100"),
32 ("explaintext", "1"), 37 ("explaintext", "1"),
33 ], 38 ],
34 ).unwrap(); 39 )
40 .unwrap();
35 41
36 let mut f = File::open("~/.taizen_logs").unwrap(); 42 let mut f = OpenOptions::new()
37 f.write_all(url.as_str().as_bytes()).unwrap(); 43 .create(true)
44 .write(true)
45 .append(true)
46 .open(dirs::home_dir().unwrap().join(".taizen_logs.txt"))
47 .unwrap();
48 writeln!(f, "{}", title).ok();
38 49
39 return url; 50 return url;
40} 51}
@@ -45,14 +56,22 @@ pub fn search_url_gen(search: &str) -> Url {
45 &[ 56 &[
46 ("action", "opensearch"), 57 ("action", "opensearch"),
47 ("format", "json"), 58 ("format", "json"),
48 ("search", &utf8_percent_encode(&search, DEFAULT_ENCODE_SET).to_string()[..]), 59 (
60 "search",
61 &utf8_percent_encode(&search, DEFAULT_ENCODE_SET).to_string()[..],
62 ),
49 ("limit", "20"), 63 ("limit", "20"),
50 ], 64 ],
51 ).unwrap(); 65 )
52 66 .unwrap();
53 let mut f = File::create("taizen_logs.txt").unwrap(); 67
54 f.write_all(url.as_str().as_bytes()).expect("failed to write unicode"); 68 let mut f = OpenOptions::new()
55 f.write_all(search.as_bytes()).unwrap(); 69 .create(true)
70 .write(true)
71 .append(true)
72 .open(dirs::home_dir().unwrap().join(".taizen_logs.txt"))
73 .unwrap();
74 writeln!(f, "{}", search).ok();
56 75
57 return url; 76 return url;
58} 77}