podal/src/lib.rs

39 lines
1 KiB
Rust

mod errors;
pub mod feed;
pub mod fetch;
pub mod file;
pub mod history;
pub mod prelude;
#[cfg(test)]
mod test_utils;
use feed::FeedEnv;
use fetch::FetchEnv;
use file::FileEnv;
use history::HistoryEnv;
use prelude::*;
pub struct Env {
pub feed: FeedEnv,
pub history: HistoryEnv,
pub fetch: FetchEnv,
pub file: FileEnv,
}
pub fn run(subscriptions: &str, history: &str, site: &str, e: Env) -> Result<()> {
for channel_name in file::read::lines_from(subscriptions, &e.file)? {
println!("Channel: {}", channel_name);
let feed_url = (e.feed.find)(site, &channel_name, &e.fetch.get)?;
for entry in (e.feed.get)(&feed_url)?.entries() {
if let Some(link) = entry.links().get(0).cloned() {
if !(e.history.find)(&link, history, &e.file)? {
println!("Downloading {}: {}", &channel_name, entry.title().as_str());
(e.fetch.download)(&link)?;
(e.history.add)(&link, history)?;
}
}
}
}
Ok(())
}