add RSS debug tool

This commit is contained in:
_ 2025-09-11 01:06:11 +00:00
parent 6daa02e8ad
commit aeaa6eb3a6
5 changed files with 206 additions and 21 deletions

View file

@ -77,25 +77,6 @@ struct CliAuto {
config: Utf8PathBuf,
}
#[derive(clap::Parser)]
struct CliDebugOutput {
#[arg(long)]
config: Utf8PathBuf,
}
#[derive(clap::Subcommand)]
enum Commands {
Auto(CliAuto),
DebugOutput(CliDebugOutput),
}
#[derive(clap::Parser)]
#[command(version, about, long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
struct Parameters {
/// Events before this time will be ignored if they cause an error
ignore_before: DateTime<chrono_tz::Tz>,
@ -484,6 +465,12 @@ fn main_auto(cli: CliAuto) -> Result<()> {
}
}
#[derive(clap::Parser)]
struct CliDebugOutput {
#[arg(long)]
config: Utf8PathBuf,
}
fn main_debug_output(cli: CliDebugOutput) -> Result<()> {
tracing_subscriber::fmt::init();
tracing::info!("Started tracing");
@ -500,11 +487,75 @@ fn main_debug_output(cli: CliDebugOutput) -> Result<()> {
Ok(())
}
#[derive(clap::Parser)]
struct CliDebugRss {
paths: Vec<Utf8PathBuf>,
}
/// Wraps rss::Item in our own type suitable for merging
struct RssItem {
channel_title: String,
date: chrono::DateTime<chrono::FixedOffset>,
inner: rss::Item,
}
fn main_debug_rss(cli: CliDebugRss) -> Result<()> {
let mut items = Vec::new();
for path in &cli.paths {
let s = std::fs::read(path)?;
let channel = rss::Channel::read_from(std::io::BufReader::new(std::io::Cursor::new(s)))?;
let channel_title = channel.title.clone();
for item in channel.into_items() {
let date = chrono::DateTime::parse_from_rfc2822(
item.pub_date()
.as_ref()
.context("Every RSS Item should have a pub_date")?,
)?;
let item = RssItem {
channel_title: channel_title.clone(),
date,
inner: item,
};
items.push(item);
}
}
items.sort_by_key(|item| item.date);
for item in &items {
println!("{}", item.channel_title);
println!("{:?}", item.inner.title);
println!("{}", item.date.to_rfc3339());
println!();
}
Ok(())
}
#[derive(clap::Subcommand)]
enum Commands {
Auto(CliAuto),
DebugOutput(CliDebugOutput),
DebugRss(CliDebugRss),
}
#[derive(clap::Parser)]
#[command(version, about, long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
fn main() -> Result<()> {
let cli = Cli::try_parse()?;
match cli.command {
Commands::Auto(x) => main_auto(x),
Commands::DebugOutput(x) => main_debug_output(x),
Commands::DebugRss(x) => main_debug_rss(x),
}
}

View file

@ -14,7 +14,7 @@ struct SillyDownloadable {
#[derive(Clone, Deserialize)]
pub(crate) struct Config {
#[serde(flatten)]
pub(crate) dl: SillyDownloadable,
dl: SillyDownloadable,
#[serde(flatten)]
pub(crate) ui: CalendarUi,