/* * SPDX-FileCopyrightText: 2024 Eilertsens Kodeknekkeri * SPDX-FileCopyrightText: 2024 Harald Eilertsen * * SPDX-License-Identifier: AGPL-3.0-or-later */ use zotapi::{ Stream, ZotApi, }; pub struct ChannelStreamCmd { } impl ChannelStreamCmd { pub async fn run(&self, client: ZotApi) -> Result<(), Box<(dyn std::error::Error + 'static)>> { let json = client.channel_stream().await?; std::fs::write("channel_stream.json", &json) .expect("Unable to write channel_stream.json file"); let s = Stream::from_json(&json)?; for item in s.items { if item.is_post() { let mut summary = item.title; if summary.len() == 0 { if item.summary.len() > 0 { summary = item.summary; } else { summary = item.body; } } summary.truncate(64); println!("{} | {:24} | {}", item.created.to_string(), item.author.name, summary); } } //println!("{}", z.channel_stream().await?); Ok(()) } }