|
|
@ -4,41 +4,16 @@ use reqwest::blocking::Client;
|
|
|
|
use clap::Parser;
|
|
|
|
use clap::Parser;
|
|
|
|
use confy;
|
|
|
|
use confy;
|
|
|
|
|
|
|
|
|
|
|
|
use std::env;
|
|
|
|
|
|
|
|
use std::process::Command;
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
|
|
|
struct Config {
|
|
|
|
|
|
|
|
user: String,
|
|
|
|
|
|
|
|
pswd: String,
|
|
|
|
|
|
|
|
note_id: String,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Default for Config {
|
|
|
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
|
|
|
Self {
|
|
|
|
|
|
|
|
user: "".to_string(),
|
|
|
|
|
|
|
|
pswd: "".to_string(),
|
|
|
|
|
|
|
|
note_id: "".to_string(),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
|
|
|
|
#[command(author, version, about, long_about=None)]
|
|
|
|
|
|
|
|
struct CliArgs {
|
|
|
|
|
|
|
|
/// Path to config .toml file
|
|
|
|
|
|
|
|
#[arg(short, long)]
|
|
|
|
|
|
|
|
config_file: String,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: logging
|
|
|
|
// TODO: logging
|
|
|
|
|
|
|
|
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
|
|
|
|
|
|
|
|
let args = CliArgs::parse();
|
|
|
|
let args = CliArgs::parse();
|
|
|
|
|
|
|
|
|
|
|
|
let cfg: Config = confy::load_path(args.config_file)?;
|
|
|
|
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 mut drives: Vec<String> = vec![];
|
|
|
|
|
|
|
|
|
|
|
@ -60,7 +35,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let mut body_content: String = String::new();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let mut drive_temps: Vec<String> = vec![];
|
|
|
|
let mut drive_temps: Vec<String> = vec![];
|
|
|
@ -71,7 +45,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
let tmp = std::str::from_utf8(&output.stdout)?.to_string();
|
|
|
|
let tmp = std::str::from_utf8(&output.stdout)?.to_string();
|
|
|
|
|
|
|
|
|
|
|
|
if !tmp.contains("sensor") {
|
|
|
|
if !tmp.contains("sensor") {
|
|
|
|
drive_temps.push(tmp.replace("\n", ""));
|
|
|
|
drive_temps.push(tmp.replace("\n", "Not running as sudo?"));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
drive_temps.push(tmp[0..9].to_string() + " No Sensor");
|
|
|
|
drive_temps.push(tmp[0..9].to_string() + " No Sensor");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -81,18 +55,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let update = Client::new()
|
|
|
|
let update = Client::new()
|
|
|
|
.put(format!("https://files.nickiel.net/index.php/apps/notes/api/v1/notes/{}", cfg.note_id.clone()))
|
|
|
|
.put(format!("https://files.nickiel.net/index.php/apps/notes/api/v1/notes/{}", cfg.note_id.clone()))
|
|
|
|
.header("Accept", "application/json")
|
|
|
|
.header("Accept", "application/json")
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
.basic_auth(cfg.user.clone(), Some(cfg.pswd.clone()))
|
|
|
|
.basic_auth(cfg.user.clone(), Some(cfg.pswd.clone()))
|
|
|
|
.body(serde_json::to_string(&NoteUpdate {content: body_content}).unwrap());
|
|
|
|
.body(serde_json::to_string(&NoteUpdate {content: body_content}).unwrap());
|
|
|
|
|
|
|
|
|
|
|
|
println!("{:#?}", update.send()?
|
|
|
|
|
|
|
|
.json::<Note>()?);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
//println!("{:#?}", update.send()?.json::<Note>()?);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -112,3 +84,28 @@ struct Note {
|
|
|
|
struct NoteUpdate {
|
|
|
|
struct NoteUpdate {
|
|
|
|
content: String,
|
|
|
|
content: String,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
|
|
|
struct Config {
|
|
|
|
|
|
|
|
user: String,
|
|
|
|
|
|
|
|
pswd: String,
|
|
|
|
|
|
|
|
note_id: String,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Default for Config {
|
|
|
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
|
|
|
Self {
|
|
|
|
|
|
|
|
user: "".to_string(),
|
|
|
|
|
|
|
|
pswd: "".to_string(),
|
|
|
|
|
|
|
|
note_id: "".to_string(),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
|
|
|
|
#[command(author, version, about, long_about=None)]
|
|
|
|
|
|
|
|
struct CliArgs {
|
|
|
|
|
|
|
|
/// Path to config .toml file
|
|
|
|
|
|
|
|
#[arg(short, long)]
|
|
|
|
|
|
|
|
config_file: String,
|
|
|
|
|
|
|
|
}
|
|
|
|