extract history::add

This commit is contained in:
Paul Campbell 2023-07-25 10:55:02 +01:00
parent 8b7c88e85c
commit a60999785b
3 changed files with 20 additions and 16 deletions

17
src/history/add.rs Normal file
View file

@ -0,0 +1,17 @@
use crate::prelude::*;
use atom_syndication::Link;
use std::fs::OpenOptions;
use std::io::prelude::*;
pub fn mark_as_downloaded(link: &Link, file_name: &str) -> Result<()> {
let mut file = OpenOptions::new()
.write(true)
.append(true)
.create(true)
.open(file_name)
.unwrap();
writeln!(file, "{}", link.href)?;
Ok(())
}

View file

@ -1,3 +1,5 @@
mod add;
mod find; mod find;
pub use add::mark_as_downloaded;
pub use find::is_already_downloaded; pub use find::is_already_downloaded;

View file

@ -21,7 +21,7 @@ pub fn run(subscriptions: &str, history: &str, site: &str) -> Result<()> {
if !history::is_already_downloaded(&link, history)? { if !history::is_already_downloaded(&link, history)? {
println!("Downloading {}: {}", &channel_name, entry.title().as_str()); println!("Downloading {}: {}", &channel_name, entry.title().as_str());
download_audio(&link)?; download_audio(&link)?;
mark_as_downloaded(&link, history)?; history::mark_as_downloaded(&link, history)?;
} }
} }
} }
@ -55,18 +55,3 @@ fn download_audio(link: &Link) -> Result<()> {
} }
Ok(()) Ok(())
} }
fn mark_as_downloaded(link: &Link, file_name: &str) -> Result<()> {
use std::fs::OpenOptions;
use std::io::prelude::*;
let mut file = OpenOptions::new()
.write(true)
.append(true)
.create(true)
.open(file_name)
.unwrap();
writeln!(file, "{}", link.href)?;
Ok(())
}