podal/src/lib.rs

40 lines
1 KiB
Rust
Raw Normal View History

2023-07-25 10:36:08 +01:00
mod errors;
pub mod feed;
pub mod fetch;
2023-07-29 19:08:52 +01:00
pub mod file;
pub mod history;
2023-07-25 10:46:47 +01:00
pub mod prelude;
2023-07-25 10:33:41 +01:00
2023-07-27 21:20:32 +01:00
#[cfg(test)]
mod test_utils;
2023-07-25 19:24:15 +01:00
use feed::FeedEnv;
use fetch::FetchEnv;
2023-07-29 19:08:52 +01:00
use file::FileEnv;
2023-07-25 19:24:15 +01:00
use history::HistoryEnv;
2023-07-25 10:46:47 +01:00
use prelude::*;
2023-07-25 10:33:41 +01:00
2023-07-25 19:24:15 +01:00
pub struct Env {
pub feed: FeedEnv,
pub history: HistoryEnv,
pub fetch: FetchEnv,
2023-07-29 19:08:52 +01:00
pub file: FileEnv,
2023-07-25 19:24:15 +01:00
}
pub fn run(subscriptions: &str, history: &str, site: &str, e: Env) -> Result<()> {
for channel_name in file::read::lines_from(subscriptions, &e.file)? {
2023-07-25 10:33:41 +01:00
println!("Channel: {}", channel_name);
2023-07-25 19:57:31 +01:00
let feed_url = (e.feed.find)(site, &channel_name, &e.fetch.get)?;
2023-07-25 19:24:15 +01:00
for entry in (e.feed.get)(&feed_url)?.entries() {
2023-07-25 10:50:31 +01:00
if let Some(link) = entry.links().get(0).cloned() {
2023-07-29 19:08:52 +01:00
if !(e.history.find)(&link, history, &e.file)? {
2023-07-25 10:33:41 +01:00
println!("Downloading {}: {}", &channel_name, entry.title().as_str());
2023-07-25 19:24:15 +01:00
(e.fetch.download)(&link)?;
(e.history.add)(&link, history)?;
2023-07-25 10:33:41 +01:00
}
}
}
}
Ok(())
}