From de4fece2454cd2dd2ad9f79dc9e3d258cdc36986 Mon Sep 17 00:00:00 2001 From: SadlyNotSappho Date: Wed, 23 Aug 2023 12:37:51 -0700 Subject: [PATCH] clean up get_home() and improve several error messages --- src/lib.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4972b48..e7ee58d 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,15 +4,13 @@ use scraper::{Html, Selector}; use serde::{Deserialize, Serialize}; pub fn get_home() -> String { - let home = match std::env::consts::OS { + match std::env::consts::OS { "linux" => std::env::var("HOME").expect("how is there not a $HOME"), "windows" => std::env::var("userprofile").expect("yell at me if this doesn't work please"), _ => std::env::var("HOME").expect( "if this doesn't work, you're probably on macos, which i literally cannot test on", ), - }; - // println!("{home}"); - home + } } pub fn create_config(file: &String) -> bool { @@ -39,13 +37,13 @@ pub fn create_config(file: &String) -> bool { pub fn read_config(file: &String) -> Config { let replaced = file.replace('~', &get_home()[..]); // replace ~ with $HOME let read = fs::read_to_string(replaced).expect("couldn't read config file"); - serde_json::from_str(&read[..]).expect("couldn't parse json") + serde_json::from_str(&read[..]).expect("couldn't parse config file's json") } pub fn ensure_exists(path: String) { let p = Path::new(&path); if !p.exists() { - fs::create_dir_all(p).expect("couldn't create folder") + fs::create_dir_all(p).expect(&format!("couldn't create folder {path}")[..]) } } @@ -70,9 +68,7 @@ pub async fn get_page(date: String) { .unwrap() .text() .await - .unwrap()[..]; - - // println!("{page_html}"); + .unwrap()[..]; // ah i love rust let parsed = Html::parse_document(page_html); @@ -83,5 +79,3 @@ pub async fn get_page(date: String) { } println!("{url}"); } - -// url: https://girlgeniusonline.com/comic.php?date={date}