summaryrefslogtreecommitdiff
path: root/src/retrieve.rs
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2026-09-05 07:05:45 +0100
committerJoe Carstairs <me@joeac.net>2026-09-05 07:28:31 +0100
commit423f5c455e1ed3586f3edf2cd81cd62bd5f91a63 (patch)
tree8220d2bbf49d64c903155444e9f301cc27d6eb35 /src/retrieve.rs
parent7101e73d22563f0ea0d0402179e8a3746e9278cc (diff)
retrieves rss feeds
Diffstat (limited to 'src/retrieve.rs')
-rw-r--r--src/retrieve.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/retrieve.rs b/src/retrieve.rs
new file mode 100644
index 0000000..ee904ab
--- /dev/null
+++ b/src/retrieve.rs
@@ -0,0 +1,24 @@
+use futures::{StreamExt, stream};
+use isahc::AsyncReadResponseExt;
+use rss::Channel;
+
+pub async fn retrieve<'a, I>(urls: I) -> Vec<Channel>
+ where I : IntoIterator<Item = &'a str>
+{
+ stream::iter(urls)
+ .flat_map(|url| stream::once(retrieve_one_or_warn(url)))
+ .filter_map(async |result| result.ok())
+ .collect().await
+}
+
+async fn retrieve_one_or_warn(url: &str) -> anyhow::Result<Channel>
+{
+ retrieve_one(url).await
+ .inspect_err(|err| eprintln!("Failed to fetch {url}: {:#?}", err))
+}
+
+async fn retrieve_one(url: &str) -> anyhow::Result<Channel>
+{
+ let content = isahc::get_async(url).await?.bytes().await?;
+ Ok(Channel::read_from(&content[..])?)
+}