diff --git a/src/cache.rs b/src/cache.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/lib.rs b/src/lib.rs index 4ee005b..41470fd 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +pub mod cache; + use std::{fs, path::Path}; use scraper::{Html, Selector}; @@ -52,8 +54,8 @@ pub fn link_to_datestring(link: String) -> String { link.split("=").collect::>().pop().unwrap().to_string() } -pub fn ensure_exists(path: String) { - let p = Path::new(&path); +pub fn ensure_exists(path: &String) { + let p = Path::new(path); if !p.exists() { fs::create_dir_all(p).expect(&format!("couldn't create folder {path}")[..]) } @@ -73,7 +75,7 @@ pub struct Page { pub image: String, } -pub async fn get_page(date: String) -> Page { +pub async fn get_page(date: &String) -> Page { let page_html = &reqwest::get(format!( "https://girlgeniusonline.com/comic.php?date={date}" )) @@ -106,7 +108,7 @@ pub async fn get_page(date: String) -> Page { } Page { - date, + date: date.clone(), next_page, prev_page, image, diff --git a/src/main.rs b/src/main.rs index ddd6194..1f8eb6f 100755 --- a/src/main.rs +++ b/src/main.rs @@ -16,10 +16,9 @@ async fn main() { ggg::create_config(&config_file); let config = ggg::read_config(&config_file); - ggg::ensure_exists(config.cache_folder); + ggg::ensure_exists(&config.cache_folder); - let current_page = ggg::get_page(config.latest_date).await; - println!("{current_page:?}"); + let current_page = ggg::get_page(&config.latest_date).await; - ggg::update_latest_date(&config_file, ggg::link_to_datestring(current_page.next_page.unwrap())); + println!("{:?}", &config); }