aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-05-02 14:29:02 +0100
committerGitHub <[email protected]>2020-05-02 14:29:02 +0100
commit5e88a55abaa2bf4356aa5bc783c2957e59c63216 (patch)
tree563d4c1c3cd63a839eb86b140d02d9a5a137d060
parentcf5fae32182d1f5a978034678d0d9d25144577d7 (diff)
parent1bf2f5603e057f8a047236a5c0fdaac9f95dc696 (diff)
Merge pull request #19 from ssiyad/masterHEADmaster
Fix log file issues
-rw-r--r--Cargo.toml1
-rw-r--r--src/content.rs43
2 files changed, 32 insertions, 12 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 73cc860..7a19546 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,3 +17,4 @@ regex = "1"
17url = "1.7.2" 17url = "1.7.2"
18clap = "2.32.0" 18clap = "2.32.0"
19lazy_static = "1.0.2" 19lazy_static = "1.0.2"
20dirs = "2.0.2"
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}