Want to contribute? Fork me on Codeberg.org!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.6 KiB

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>> {
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")
.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>()?);
Ok(())
}
#[derive(Serialize, Deserialize, Debug)]
struct Note {
id: usize,
etag: String,
readonly: bool,
modified: u64,
title: String,
category: String,
content: String,
favorite: bool
1 year ago
}
#[derive(Serialize, Deserialize, Debug)]
struct NoteUpdate {
content: String,
}