aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/bitcoins.rs26
-rw-r--r--src/utils/mod.rs1
-rw-r--r--src/utils/netspeed.rs2
-rw-r--r--src/utils/pub_ip.rs2
4 files changed, 29 insertions, 2 deletions
diff --git a/src/utils/bitcoins.rs b/src/utils/bitcoins.rs
new file mode 100644
index 0000000..465d907
--- /dev/null
+++ b/src/utils/bitcoins.rs
@@ -0,0 +1,26 @@
+use crate::config::CONFIG;
+use crate::types::ThreadsData;
+use serde::Deserialize;
+
+#[derive(Deserialize)]
+struct Response {
+ price_24h: f64,
+}
+
+pub fn get_price() -> ThreadsData {
+ let url = format!(
+ "https://api.blockchain.com/v3/exchange/tickers/{}",
+ CONFIG.bitcoins.symbol
+ );
+ let _err = String::from("Error");
+ let res = match minreq::get(url).send() {
+ Ok(resp) => match resp.json::<Response>() {
+ Ok(data) => data.price_24h.to_string(),
+ _ => _err,
+ },
+ Err(_) => _err,
+ };
+
+ let data = format!(" {} {} {}", CONFIG.bitcoins.icon, res, CONFIG.seperator);
+ ThreadsData::BitCoins(data)
+}
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index e70cf88..22b4bad 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -1,4 +1,5 @@
pub mod battery;
+pub mod bitcoins;
pub mod cpu;
pub mod disk;
pub mod load_average;
diff --git a/src/utils/netspeed.rs b/src/utils/netspeed.rs
index fe172a3..16caaa4 100644
--- a/src/utils/netspeed.rs
+++ b/src/utils/netspeed.rs
@@ -26,7 +26,7 @@ pub fn get_netspeed() -> ThreadsData {
fn parse_speed_file(pth: &str) -> u64 {
let base_path = format!("/sys/class/net/{}/statistics/", CONFIG.netspeed.interface);
- let x: u64 = read_to_string(base_path.to_owned() + pth)
+ let x: u64 = read_to_string(base_path + pth)
.unwrap()
.trim()
.parse::<u64>()
diff --git a/src/utils/pub_ip.rs b/src/utils/pub_ip.rs
index c0e6e4c..4f1335f 100644
--- a/src/utils/pub_ip.rs
+++ b/src/utils/pub_ip.rs
@@ -2,7 +2,7 @@ use crate::config::CONFIG;
use crate::types::ThreadsData;
pub fn get_pub_ip() -> ThreadsData {
- let url = format!("http://api.ipify.org");
+ let url = "http://api.ipify.org".to_string();
let _err = String::from("Error");
let res = match minreq::get(url).send() {
Ok(resp) => match resp.as_str() {