diff --git a/src/lib.rs b/src/lib.rs index 4e07e73..4ee005b 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,6 +40,18 @@ pub fn read_config(file: &String) -> Config { serde_json::from_str(&read[..]).expect("couldn't parse config file's json") } +pub fn update_latest_date(file: &String, new_date: String) { + let mut prevconfig = read_config(file); + prevconfig.latest_date = new_date; + + let newconfig = serde_json::to_string(&prevconfig).expect("couldn't serialize json data"); + fs::write(file.replace('~', &get_home()[..]), newconfig).expect("couldn't write to config file"); +} + +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); if !p.exists() { @@ -47,7 +59,7 @@ pub fn ensure_exists(path: String) { } } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] pub struct Config { pub latest_date: String, pub cache_folder: String, diff --git a/src/main.rs b/src/main.rs index 26aa5b9..ddd6194 100755 --- a/src/main.rs +++ b/src/main.rs @@ -20,4 +20,6 @@ async fn main() { let current_page = ggg::get_page(config.latest_date).await; println!("{current_page:?}"); + + ggg::update_latest_date(&config_file, ggg::link_to_datestring(current_page.next_page.unwrap())); }