Support multiple feeds
This commit is contained in:
18
src/main.rs
18
src/main.rs
@@ -7,13 +7,21 @@ use feed_rs::{
|
||||
model::Feed,
|
||||
};
|
||||
|
||||
fn fetch_feed() -> Result<Feed> {
|
||||
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<Feed> {
|
||||
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("<ul>\n");
|
||||
|
||||
for item in feed.entries {
|
||||
out.push_str(&format!("<li><a href=\"{}\">{}</a></li>\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!("<li><a href=\"{}\">{}</a> ({})</li>\n", item.links.first().context("No link found")?.href, item.title.context("No title found")?.content, item.published.context("")?));
|
||||
}
|
||||
|
||||
out.push_str("</ul>\n");
|
||||
|
Reference in New Issue
Block a user