Ready for nix testing
This commit is contained in:
parent
afa0cd2218
commit
a50efdeea0
4 changed files with 187 additions and 95 deletions
|
@ -4,9 +4,87 @@ use reqwest::blocking::Client;
|
|||
use clap::Parser;
|
||||
use confy;
|
||||
|
||||
use std::env;
|
||||
use std::process::Command;
|
||||
|
||||
|
||||
// TODO: logging
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let args = CliArgs::parse();
|
||||
let cfg: Config = confy::load_path(args.config_file)?;
|
||||
let mut body_content: String = format!("*Last Updated:* {} \n", chrono::Local::now().format("%D - %H:%M:%S"));
|
||||
|
||||
let mut drives: Vec<String> = vec![];
|
||||
|
||||
{
|
||||
let rust_drives = std::fs::read_dir("/dev/").unwrap();
|
||||
|
||||
for path in rust_drives {
|
||||
match path {
|
||||
Ok(ref val) => {
|
||||
let tmp = val.path().to_string_lossy().to_string();
|
||||
if tmp.starts_with("/dev/sd") {
|
||||
if tmp.len() == 8 {
|
||||
drives.push(tmp);
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
let mut drive_temps: Vec<String> = vec![];
|
||||
|
||||
for drive in drives {
|
||||
let output = Command::new("hddtemp").arg(drive).output()?;
|
||||
|
||||
let tmp = std::str::from_utf8(&output.stdout)?.to_string();
|
||||
|
||||
if !tmp.contains("sensor") {
|
||||
drive_temps.push(tmp.replace("\n", "Not running as sudo?"));
|
||||
} else {
|
||||
drive_temps.push(tmp[0..9].to_string() + " No Sensor");
|
||||
}
|
||||
}
|
||||
body_content.push_str("## Hard Drive Temps\n");
|
||||
body_content.push_str(drive_temps.join("\n").as_str());
|
||||
}
|
||||
|
||||
|
||||
let update = Client::new()
|
||||
.put(format!("https://files.nickiel.net/index.php/apps/notes/api/v1/notes/{}", cfg.note_id.clone()))
|
||||
.header("Accept", "application/json")
|
||||
.header("Content-Type", "application/json")
|
||||
.basic_auth(cfg.user.clone(), Some(cfg.pswd.clone()))
|
||||
.body(serde_json::to_string(&NoteUpdate {content: body_content}).unwrap());
|
||||
|
||||
//println!("{:#?}", update.send()?.json::<Note>()?);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct Note {
|
||||
id: usize,
|
||||
etag: String,
|
||||
readonly: bool,
|
||||
modified: u64,
|
||||
title: String,
|
||||
category: String,
|
||||
content: String,
|
||||
favorite: bool
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct NoteUpdate {
|
||||
content: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Config {
|
||||
user: String,
|
||||
|
@ -31,84 +109,3 @@ struct CliArgs {
|
|||
#[arg(short, long)]
|
||||
config_file: String,
|
||||
}
|
||||
|
||||
// TODO: logging
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let args = CliArgs::parse();
|
||||
|
||||
let cfg: Config = confy::load_path(args.config_file)?;
|
||||
|
||||
let mut drives: Vec<String> = vec![];
|
||||
|
||||
{
|
||||
let rust_drives = std::fs::read_dir("/dev/").unwrap();
|
||||
|
||||
for path in rust_drives {
|
||||
match path {
|
||||
Ok(ref val) => {
|
||||
let tmp = val.path().to_string_lossy().to_string();
|
||||
if tmp.starts_with("/dev/sd") {
|
||||
if tmp.len() == 8 {
|
||||
drives.push(tmp);
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut body_content: String = String::new();
|
||||
|
||||
{
|
||||
let mut drive_temps: Vec<String> = vec![];
|
||||
|
||||
for drive in drives {
|
||||
let output = Command::new("hddtemp").arg(drive).output()?;
|
||||
|
||||
let tmp = std::str::from_utf8(&output.stdout)?.to_string();
|
||||
|
||||
if !tmp.contains("sensor") {
|
||||
drive_temps.push(tmp.replace("\n", ""));
|
||||
} else {
|
||||
drive_temps.push(tmp[0..9].to_string() + " No Sensor");
|
||||
}
|
||||
}
|
||||
body_content.push_str("## Hard Drive Temps\n");
|
||||
body_content.push_str(drive_temps.join("\n").as_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
let update = Client::new()
|
||||
.put(format!("https://files.nickiel.net/index.php/apps/notes/api/v1/notes/{}", cfg.note_id.clone()))
|
||||
.header("Accept", "application/json")
|
||||
.header("Content-Type", "application/json")
|
||||
.basic_auth(cfg.user.clone(), Some(cfg.pswd.clone()))
|
||||
.body(serde_json::to_string(&NoteUpdate {content: body_content}).unwrap());
|
||||
|
||||
println!("{:#?}", update.send()?
|
||||
.json::<Note>()?);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct Note {
|
||||
id: usize,
|
||||
etag: String,
|
||||
readonly: bool,
|
||||
modified: u64,
|
||||
title: String,
|
||||
category: String,
|
||||
content: String,
|
||||
favorite: bool
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct NoteUpdate {
|
||||
content: String,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue