feat: Atom feed
This commit is contained in:
Generated
+2
-1
@@ -840,8 +840,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rss_library"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"atom_syndication",
|
||||
"reqwest",
|
||||
"rss",
|
||||
"serde",
|
||||
|
||||
+2
-1
@@ -1,10 +1,11 @@
|
||||
[package]
|
||||
name = "rss_library"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
rss = "2.0.12"
|
||||
atom_syndication = "0.12.7"
|
||||
|
||||
[dependencies.reqwest]
|
||||
version = "0.12.15"
|
||||
|
||||
+24
@@ -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
@@ -1,29 +1,3 @@
|
||||
use rss::{Channel, Guid, Item};
|
||||
use std::error::Error;
|
||||
|
||||
pub mod discord;
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
pub mod rss;
|
||||
pub mod atom;
|
||||
+24
@@ -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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user