feat: Atom feed

This commit is contained in:
2025-12-20 11:11:09 +01:00
parent c865fe9d97
commit 61bbc6acc5
5 changed files with 54 additions and 30 deletions
Generated
+2 -1
View File
@@ -840,8 +840,9 @@ dependencies = [
[[package]] [[package]]
name = "rss_library" name = "rss_library"
version = "0.1.0" version = "0.2.0"
dependencies = [ dependencies = [
"atom_syndication",
"reqwest", "reqwest",
"rss", "rss",
"serde", "serde",
+2 -1
View File
@@ -1,10 +1,11 @@
[package] [package]
name = "rss_library" name = "rss_library"
version = "0.1.0" version = "0.2.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
rss = "2.0.12" rss = "2.0.12"
atom_syndication = "0.12.7"
[dependencies.reqwest] [dependencies.reqwest]
version = "0.12.15" version = "0.12.15"
+24
View File
@@ -0,0 +1,24 @@
use std::error::Error;
use atom_syndication::{Entry, Feed};
pub async fn get_content(source: &str) -> Result<Feed, Box<dyn Error>> {
let content = reqwest::get(source).await?.bytes().await?;
let channel = Feed::read_from(&content[..])?;
Ok(channel)
}
pub fn get_latest(rss: &Feed) -> Option<&Entry> {
rss.entries().first()
}
pub fn get_new<'a>(feed: &'a Feed, latest: &str) -> &'a [Entry] {
match feed
.entries()
.iter()
.position(|entry| entry.id() == latest)
.map(|i| &feed.entries()[0..i])
{
None => feed.entries(),
Some(list) => list,
}
}
+2 -28
View File
@@ -1,29 +1,3 @@
use rss::{Channel, Guid, Item};
use std::error::Error;
pub mod discord; pub mod discord;
pub mod rss;
pub async fn get_content(source: &str) -> Result<Channel, Box<dyn Error>> { pub mod atom;
let content = reqwest::get(source)
.await?
.bytes()
.await?;
let channel = Channel::read_from(&content[..])?;
Ok(channel)
}
pub fn get_latest(rss: &Channel) -> Option<&Item> {
rss.items().first()
}
pub fn get_new<'a>(rss: &'a Channel, latest: &Guid) -> &'a [Item] {
match rss
.items()
.iter()
.position(|item| item.guid().map(|guid| guid == latest).unwrap_or(false))
.map(|i| &rss.items()[0..i])
{
None => rss.items(),
Some(list) => list,
}
}
+24
View File
@@ -0,0 +1,24 @@
use rss::{Channel, Guid, Item};
use std::error::Error;
pub async fn get_content(source: &str) -> Result<Channel, Box<dyn Error>> {
let content = reqwest::get(source).await?.bytes().await?;
let channel = Channel::read_from(&content[..])?;
Ok(channel)
}
pub fn get_latest(rss: &Channel) -> Option<&Item> {
rss.items().first()
}
pub fn get_new<'a>(rss: &'a Channel, latest: &Guid) -> &'a [Item] {
match rss
.items()
.iter()
.position(|item| item.guid().map(|guid| guid == latest).unwrap_or(false))
.map(|i| &rss.items()[0..i])
{
None => rss.items(),
Some(list) => list,
}
}