From 6bf6b6719073d3b0d65be05dd626296dda590406 Mon Sep 17 00:00:00 2001 From: axtloss <3alouchi2006@gmail.com> Date: Wed, 21 Jul 2021 17:09:03 +0200 Subject: [PATCH] added code to get the arch rpc json and write it into variable --- Cargo.toml | 4 +++- src/search.rs | 32 ++++++++++++++------------------ wget-log | 11 +++++++++++ wget-log.1 | 11 +++++++++++ wget-log.2 | 11 +++++++++++ wget-log.3 | 11 +++++++++++ wget-log.4 | 11 +++++++++++ wget-log.5 | 11 +++++++++++ wget-log.6 | 11 +++++++++++ wget-log.7 | 11 +++++++++++ wget-log.8 | 11 +++++++++++ 11 files changed, 116 insertions(+), 19 deletions(-) create mode 100644 wget-log create mode 100644 wget-log.1 create mode 100644 wget-log.2 create mode 100644 wget-log.3 create mode 100644 wget-log.4 create mode 100644 wget-log.5 create mode 100644 wget-log.6 create mode 100644 wget-log.7 create mode 100644 wget-log.8 diff --git a/Cargo.toml b/Cargo.toml index 1374944..68f08c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,6 @@ edition = "2018" git2 = "*" serde_json = "*" ureq = "*" -json = "*" \ No newline at end of file +json = "*" +cargo = "*" +curl = "*" \ No newline at end of file diff --git a/src/search.rs b/src/search.rs index 246d2e5..69bc8f7 100644 --- a/src/search.rs +++ b/src/search.rs @@ -3,26 +3,22 @@ use json; use std::fs::File; use std::io::prelude::*; use std::path::Path; -use std::env; +use curl::easy::Easy; +use std::io::{stdout, Write}; pub fn search(pkg: &str) { - let homedir = env::home_dir(); - match homedir { - Some(homedirr) => println!("{}",homedirr.display()), - None => panic!("could not read home dir") - } - Command::new("pacman").arg("-Ss").arg(&pkg).spawn(); - let search_path = Path::new("/Users/ali/search.json"); //TODO: make it use a relative path to the search - let display = search_path.display(); + let url = format!("https://aur.archlinux.org/rpc/?v=5&type=search&arg={}",&pkg); + + let mut easy = Easy::new(); + easy.url(&url).unwrap(); + easy.write_function(|data| { + stdout().write_all(data).unwrap(); + Ok(data.len()) + }).unwrap(); + easy.perform().unwrap(); - let mut searchfile = match File::open(&search_path) { - Err(why) => panic!("couldnt read {}: {}", display, why), - Ok(searchfile) => searchfile, - }; + let output = easy.response_code().unwrap(); + println!("{}", output); - let mut content = String::new(); - match searchfile.read_to_string(&mut content) { - Err(why) => panic!("Couldnt read {}: {}", display, why), - Ok(_) => print!("{}", content), - }; + Command::new("pacman").arg("-Ss").arg(&pkg).spawn().expect("Failed to run pacman"); } \ No newline at end of file diff --git a/wget-log b/wget-log new file mode 100644 index 0000000..42de70d --- /dev/null +++ b/wget-log @@ -0,0 +1,11 @@ +--2021-07-21 16:26:17-- https://aur.archlinux.org/rpc/?v=5&type=search&arg=neofetch +Resolving aur.archlinux.org (aur.archlinux.org)... 2a01:4f9:c010:50::1, 95.216.144.15 +Connecting to aur.archlinux.org (aur.archlinux.org)|2a01:4f9:c010:50::1|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [application/json] +Saving to: ‘/Users/ali/.cache/ame/search.json’ + + /Users/ali/.cache/ame/search.json [<=> ] 0 --.-KB/s /Users/ali/.cache/ame/search.json [ <=> ] 4.49K --.-KB/s in 0s + +2021-07-21 16:26:18 (487 MB/s) - ‘/Users/ali/.cache/ame/search.json’ saved [4600] + diff --git a/wget-log.1 b/wget-log.1 new file mode 100644 index 0000000..b3360fa --- /dev/null +++ b/wget-log.1 @@ -0,0 +1,11 @@ +--2021-07-21 16:26:27-- https://aur.archlinux.org/rpc/?v=5&type=search&arg=neofetch +Resolving aur.archlinux.org (aur.archlinux.org)... 2a01:4f9:c010:50::1, 95.216.144.15 +Connecting to aur.archlinux.org (aur.archlinux.org)|2a01:4f9:c010:50::1|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [application/json] +Saving to: ‘/Users/ali/.cache/ame/search.json’ + + /Users/ali/.cache/ame/search.json [<=> ] 0 --.-KB/s /Users/ali/.cache/ame/search.json [ <=> ] 4.49K --.-KB/s in 0s + +2021-07-21 16:26:27 (399 MB/s) - ‘/Users/ali/.cache/ame/search.json’ saved [4600] + diff --git a/wget-log.2 b/wget-log.2 new file mode 100644 index 0000000..35f6511 --- /dev/null +++ b/wget-log.2 @@ -0,0 +1,11 @@ +--2021-07-21 16:28:31-- https://aur.archlinux.org/rpc/?v=5&type=search&arg=neofetch +Resolving aur.archlinux.org (aur.archlinux.org)... 2a01:4f9:c010:50::1, 95.216.144.15 +Connecting to aur.archlinux.org (aur.archlinux.org)|2a01:4f9:c010:50::1|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [application/json] +Saving to: ‘/Users/ali/.cache/ame/search.json’ + + /Users/ali/.cache/ame/search.json [<=> ] 0 --.-KB/s /Users/ali/.cache/ame/search.json [ <=> ] 4.49K --.-KB/s in 0s + +2021-07-21 16:28:32 (337 MB/s) - ‘/Users/ali/.cache/ame/search.json’ saved [4600] + diff --git a/wget-log.3 b/wget-log.3 new file mode 100644 index 0000000..7ec7fcc --- /dev/null +++ b/wget-log.3 @@ -0,0 +1,11 @@ +--2021-07-21 16:28:46-- https://aur.archlinux.org/rpc/?v=5&type=search&arg=neofetch +Resolving aur.archlinux.org (aur.archlinux.org)... 2a01:4f9:c010:50::1, 95.216.144.15 +Connecting to aur.archlinux.org (aur.archlinux.org)|2a01:4f9:c010:50::1|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [application/json] +Saving to: ‘/Users/ali/.cache/ame/search.json’ + + /Users/ali/.cache/ame/search.json [<=> ] 0 --.-KB/s /Users/ali/.cache/ame/search.json [ <=> ] 4.49K --.-KB/s in 0s + +2021-07-21 16:28:46 (258 MB/s) - ‘/Users/ali/.cache/ame/search.json’ saved [4600] + diff --git a/wget-log.4 b/wget-log.4 new file mode 100644 index 0000000..01a3712 --- /dev/null +++ b/wget-log.4 @@ -0,0 +1,11 @@ +--2021-07-21 16:39:47-- https://aur.archlinux.org/rpc/?v=5&type=search&arg=neofetch +Resolving aur.archlinux.org (aur.archlinux.org)... 2a01:4f9:c010:50::1, 95.216.144.15 +Connecting to aur.archlinux.org (aur.archlinux.org)|2a01:4f9:c010:50::1|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [application/json] +Saving to: ‘/Users/ali/.cache/ame/search.json’ + + /Users/ali/.cache/ame/search.json [<=> ] 0 --.-KB/s /Users/ali/.cache/ame/search.json [ <=> ] 4.49K --.-KB/s in 0s + +2021-07-21 16:39:47 (292 MB/s) - ‘/Users/ali/.cache/ame/search.json’ saved [4600] + diff --git a/wget-log.5 b/wget-log.5 new file mode 100644 index 0000000..8da7659 --- /dev/null +++ b/wget-log.5 @@ -0,0 +1,11 @@ +--2021-07-21 16:39:55-- https://aur.archlinux.org/rpc/?v=5&type=search&arg=neofetch +Resolving aur.archlinux.org (aur.archlinux.org)... 2a01:4f9:c010:50::1, 95.216.144.15 +Connecting to aur.archlinux.org (aur.archlinux.org)|2a01:4f9:c010:50::1|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [application/json] +Saving to: ‘/Users/ali/.cache/ame/search.json’ + + /Users/ali/.cache/ame/search.json [<=> ] 0 --.-KB/s /Users/ali/.cache/ame/search.json [ <=> ] 4.49K --.-KB/s in 0s + +2021-07-21 16:39:55 (548 MB/s) - ‘/Users/ali/.cache/ame/search.json’ saved [4600] + diff --git a/wget-log.6 b/wget-log.6 new file mode 100644 index 0000000..952b725 --- /dev/null +++ b/wget-log.6 @@ -0,0 +1,11 @@ +--2021-07-21 16:56:52-- https://aur.archlinux.org/rpc/?v=5&type=search&arg=neofetch +Resolving aur.archlinux.org (aur.archlinux.org)... 2a01:4f9:c010:50::1, 95.216.144.15 +Connecting to aur.archlinux.org (aur.archlinux.org)|2a01:4f9:c010:50::1|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [application/json] +Saving to: ‘/Users/ali/.cache/ame/search.json’ + + /Users/ali/.cache/ame/search.json [<=> ] 0 --.-KB/s /Users/ali/.cache/ame/search.json [ <=> ] 4.49K --.-KB/s in 0s + +2021-07-21 16:56:52 (231 MB/s) - ‘/Users/ali/.cache/ame/search.json’ saved [4600] + diff --git a/wget-log.7 b/wget-log.7 new file mode 100644 index 0000000..31e01f1 --- /dev/null +++ b/wget-log.7 @@ -0,0 +1,11 @@ +--2021-07-21 17:06:39-- https://aur.archlinux.org/rpc/?v=5&type=search&arg=neofetch +Resolving aur.archlinux.org (aur.archlinux.org)... 2a01:4f9:c010:50::1, 95.216.144.15 +Connecting to aur.archlinux.org (aur.archlinux.org)|2a01:4f9:c010:50::1|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [application/json] +Saving to: ‘/Users/ali/.cache/ame/search.json’ + + /Users/ali/.cache/ame/search.json [<=> ] 0 --.-KB/s /Users/ali/.cache/ame/search.json [ <=> ] 4.49K --.-KB/s in 0s + +2021-07-21 17:06:39 (258 MB/s) - ‘/Users/ali/.cache/ame/search.json’ saved [4600] + diff --git a/wget-log.8 b/wget-log.8 new file mode 100644 index 0000000..69214b0 --- /dev/null +++ b/wget-log.8 @@ -0,0 +1,11 @@ +--2021-07-21 17:07:54-- https://aur.archlinux.org/rpc/?v=5&type=search&arg=neofetch +Resolving aur.archlinux.org (aur.archlinux.org)... 2a01:4f9:c010:50::1, 95.216.144.15 +Connecting to aur.archlinux.org (aur.archlinux.org)|2a01:4f9:c010:50::1|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [application/json] +Saving to: ‘/Users/ali/.cache/ame/search.json’ + + /Users/ali/.cache/ame/search.json [<=> ] 0 --.-KB/s /Users/ali/.cache/ame/search.json [ <=> ] 4.49K --.-KB/s in 0s + +2021-07-21 17:07:55 (487 MB/s) - ‘/Users/ali/.cache/ame/search.json’ saved [4600] +