From bce81ef67b78ab431f285fb709ef973ec3b0ada1 Mon Sep 17 00:00:00 2001 From: clerie Date: Fri, 29 Nov 2024 21:38:30 +0100 Subject: [PATCH] Support multiple feeds --- Cargo.lock | 1 + Cargo.toml | 1 + src/main.rs | 18 +++++++++++++----- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 74b0295..9f9701b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -837,6 +837,7 @@ name = "rainbowrss" version = "0.1.0" dependencies = [ "anyhow", + "chrono", "feed-rs", "reqwest", ] diff --git a/Cargo.toml b/Cargo.toml index d026817..329a141 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,5 +5,6 @@ edition = "2021" [dependencies] anyhow = "1.0.93" +chrono = "0.4.38" feed-rs = "2.2.0" reqwest = { version = "0.12.9", features = ["blocking"] } diff --git a/src/main.rs b/src/main.rs index 0e313d9..8d62e91 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,13 +7,21 @@ use feed_rs::{ model::Feed, }; -fn fetch_feed() -> Result { - let content = reqwest::blocking::get("https://www.youtube.com/feeds/videos.xml?channel_id=UC0intLFzLaudFG-xAvUEO-A")?.bytes()?; +use reqwest::IntoUrl; + +fn fetch_feed(url: impl IntoUrl) -> Result { + let content = reqwest::blocking::get(url)?.bytes()?; Ok(parse(&content[..])?) } fn main() -> Result<()> { - let feed = fetch_feed()?; + + let mut feed_items = Vec::new(); + + feed_items.extend(fetch_feed("https://www.youtube.com/feeds/videos.xml?channel_id=UC0intLFzLaudFG-xAvUEO-A")?.entries); + feed_items.extend(fetch_feed("https://feed.zugfunk-podcast.de/")?.entries); + + feed_items.sort_by(|a, b| a.published.unwrap_or(chrono::DateTime::UNIX_EPOCH).cmp(&b.published.unwrap_or(chrono::DateTime::UNIX_EPOCH)).reverse()); let mut out = String::new(); @@ -25,8 +33,8 @@ fn main() -> Result<()> { out.push_str("
    \n"); - for item in feed.entries { - out.push_str(&format!("
  • {}
  • \n", item.links.first().context("No link found")?.href, item.title.context("No title found")?.content)); + for item in feed_items { + out.push_str(&format!("
  • {} ({})
  • \n", item.links.first().context("No link found")?.href, item.title.context("No title found")?.content, item.published.context("")?)); } out.push_str("
\n");