|
|
|
@ -1,15 +1,78 @@
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
use reqwest::blocking::Client;
|
|
|
|
|
|
|
|
|
|
use dotenv::dotenv;
|
|
|
|
|
use std::env;
|
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
|
let client = Client::new();
|
|
|
|
|
let res = client
|
|
|
|
|
.get("https://username:password@files.nickiel.net/index.php/apps/notes/api/v1/notes")
|
|
|
|
|
dotenv().ok();
|
|
|
|
|
|
|
|
|
|
let user = env::var("NEXTCLOUD_USER").unwrap();
|
|
|
|
|
let pswd = env::var("NEXTCLOUD_PWD").unwrap();
|
|
|
|
|
let note_id = env::var("NOTE_ID").unwrap();
|
|
|
|
|
|
|
|
|
|
// let client = Client::new();
|
|
|
|
|
// let res = client
|
|
|
|
|
// .get(format!("https://files.nickiel.net/index.php/apps/notes/api/v1/notes/{}", note_id))
|
|
|
|
|
// .header("Accept", "application/json")
|
|
|
|
|
// .basic_auth(user.clone(), Some(pswd.clone()))
|
|
|
|
|
// .send()?
|
|
|
|
|
// .json::<Note>()?;
|
|
|
|
|
// println!("{:#?}", res);
|
|
|
|
|
|
|
|
|
|
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/{}", note_id))
|
|
|
|
|
.header("Accept", "application/json")
|
|
|
|
|
.send()?
|
|
|
|
|
.json::<Vec<Note>>()?;
|
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
|
.basic_auth(user, Some(pswd))
|
|
|
|
|
.body(serde_json::to_string(&NoteUpdate {content: body_content}).unwrap());
|
|
|
|
|
|
|
|
|
|
println!("{:#?}", update.send()?
|
|
|
|
|
.json::<Note>()?);
|
|
|
|
|
|
|
|
|
|
println!("{:#?}", res);
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -25,3 +88,8 @@ struct Note {
|
|
|
|
|
content: String,
|
|
|
|
|
favorite: bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
|
|
|
struct NoteUpdate {
|
|
|
|
|
content: String,
|
|
|
|
|
}
|
|
|
|
|