From 0b6903404a46b7c8ca017f8b30e5fc75de03df59 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 25 Jul 2023 10:50:00 +0100 Subject: [PATCH] extract feed::get --- src/feed/get.rs | 9 +++++++++ src/feed/mod.rs | 2 ++ src/lib.rs | 11 ++--------- 3 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 src/feed/get.rs diff --git a/src/feed/get.rs b/src/feed/get.rs new file mode 100644 index 0000000..5288c6b --- /dev/null +++ b/src/feed/get.rs @@ -0,0 +1,9 @@ +use atom_syndication::Feed; + +use crate::prelude::*; + +pub fn get_feed(url: String) -> Result { + let content = reqwest::blocking::get(url)?.bytes()?; + let channel = Feed::read_from(&content[..])?; + Ok(channel) +} diff --git a/src/feed/mod.rs b/src/feed/mod.rs index 385ab7d..1b9943a 100644 --- a/src/feed/mod.rs +++ b/src/feed/mod.rs @@ -1,3 +1,5 @@ mod find; +mod get; pub use find::get_feed_url; +pub use get::get_feed; diff --git a/src/lib.rs b/src/lib.rs index 3702f3a..ca157c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ use std::fs::File; -use atom_syndication::{Entry, Feed, Link}; +use atom_syndication::{Entry, Link}; mod errors; mod feed; @@ -15,7 +15,7 @@ pub fn run(subscriptions: &str, history: &str, site: &str) -> Result<()> { let channel_name = channel_name?; println!("Channel: {}", channel_name); let feed_url = feed::get_feed_url(site, &channel_name)?; - for entry in get_feed(feed_url)?.entries() { + for entry in feed::get_feed(feed_url)?.entries() { if let Some(link) = get_link(entry) { if !is_already_downloaded(&link, history)? { println!("Downloading {}: {}", &channel_name, entry.title().as_str()); @@ -41,13 +41,6 @@ fn lines_from(file_name: &str) -> Result Result { - let content = reqwest::blocking::get(url)?.bytes()?; - let channel = Feed::read_from(&content[..])?; - Ok(channel) -} - fn is_already_downloaded(link: &Link, file_name: &str) -> Result { use std::io::{BufRead, BufReader};