working push to notes api

main
Nickiel12 1 year ago
parent 5fe2d9b599
commit 7677eb1425

4
.gitignore vendored

@ -1,2 +1,4 @@
/target
.direnv
.direnv
.env

8
Cargo.lock generated

@ -99,6 +99,12 @@ version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
[[package]]
name = "dotenv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]]
name = "encoding_rs"
version = "0.8.32"
@ -726,8 +732,10 @@ dependencies = [
name = "status_cloud"
version = "0.1.0"
dependencies = [
"dotenv",
"reqwest",
"serde",
"serde_json",
]
[[package]]

@ -6,5 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
dotenv = "0.15.0"
reqwest = { version = "0.11.18", features = ["blocking", "json"] }
serde = { version = "1.0.184", features = ["serde_derive"] }
serde_json = "1.0.105"

@ -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,
}

Loading…
Cancel
Save