use anyhow::{Context, Error, Result}; use chrono::{Days, NaiveTime, Utc}; use mininews::parser::{parse, EventBlock, PAGE_URL}; use rss::{ChannelBuilder, Guid, Item, ItemBuilder}; use uuid::{Timestamp, Uuid}; fn generate_feed(items: Vec) -> Result<()> { let mut channel = ChannelBuilder::default() .title("Mininews") .link("https://example.com") .description("An RSS feed from Wikipedia's Current Events") .build(); channel.set_items( items .iter() .filter(|x| x.date < Utc::now().date_naive()) .map(|x| { let pub_date = x .date .checked_add_days(Days::new(1)) .context("failed to add to date")? .and_time(NaiveTime::MIN) .and_utc(); Ok::( ItemBuilder::default() .title(x.date.to_string()) .link(Some(PAGE_URL.to_string())) .pub_date(pub_date.to_rfc2822()) .guid(Guid { permalink: false, value: Uuid::new_v7(Timestamp::from_unix_time( pub_date.timestamp() as u64, 0, 0, 0, )) .to_string(), }) .description(format!( "Wikipedia current events from {}", x.date.to_string() )) .content(x.content.clone()) .build(), ) }) .collect::, _>>()?, ); println!("{:?}", channel.to_string()); Ok(()) } fn main() -> Result<()> { generate_feed(parse()?) }