i5-add-tests #6

Merged
kemitix merged 14 commits from i5-add-tests into main 2023-07-25 16:59:24 +01:00
3 changed files with 20 additions and 16 deletions
Showing only changes of commit a60999785b - Show all commits

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(())
}