.clone() is a crime against humanity, but sometimes those can be a good thing

This commit is contained in:
SadlyNotSappho 2023-08-25 12:52:08 -07:00
parent d55c600eee
commit f2d40849db
3 changed files with 9 additions and 8 deletions

0
src/cache.rs Normal file
View File

View File

@ -1,3 +1,5 @@
pub mod cache;
use std::{fs, path::Path}; use std::{fs, path::Path};
use scraper::{Html, Selector}; use scraper::{Html, Selector};
@ -52,8 +54,8 @@ pub fn link_to_datestring(link: String) -> String {
link.split("=").collect::<Vec<&str>>().pop().unwrap().to_string() link.split("=").collect::<Vec<&str>>().pop().unwrap().to_string()
} }
pub fn ensure_exists(path: String) { pub fn ensure_exists(path: &String) {
let p = Path::new(&path); let p = Path::new(path);
if !p.exists() { if !p.exists() {
fs::create_dir_all(p).expect(&format!("couldn't create folder {path}")[..]) fs::create_dir_all(p).expect(&format!("couldn't create folder {path}")[..])
} }
@ -73,7 +75,7 @@ pub struct Page {
pub image: String, 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!( let page_html = &reqwest::get(format!(
"https://girlgeniusonline.com/comic.php?date={date}" "https://girlgeniusonline.com/comic.php?date={date}"
)) ))
@ -106,7 +108,7 @@ pub async fn get_page(date: String) -> Page {
} }
Page { Page {
date, date: date.clone(),
next_page, next_page,
prev_page, prev_page,
image, image,

View File

@ -16,10 +16,9 @@ async fn main() {
ggg::create_config(&config_file); ggg::create_config(&config_file);
let config = ggg::read_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; 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())); println!("{:?}", &config);
} }