diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2024-10-30 20:23:56 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2024-10-30 20:23:56 +0100 |
commit | 0f32f1d37c95818bc4ced69f09befe9320026611 (patch) | |
tree | 4cabd6fdfafff2aa245ed52a2adbcd824a9ed50f /src/bin/zot/command/channel | |
parent | 7daf82cb395e3612736eebae3fe699dae6d790b1 (diff) | |
download | rust-zotapi-0f32f1d37c95818bc4ced69f09befe9320026611.tar.gz rust-zotapi-0f32f1d37c95818bc4ced69f09befe9320026611.tar.bz2 rust-zotapi-0f32f1d37c95818bc4ced69f09befe9320026611.zip |
Add command module and move implementations to it.
Diffstat (limited to 'src/bin/zot/command/channel')
-rw-r--r-- | src/bin/zot/command/channel/export.rs | 19 | ||||
-rw-r--r-- | src/bin/zot/command/channel/list.rs | 21 | ||||
-rw-r--r-- | src/bin/zot/command/channel/stream.rs | 47 |
3 files changed, 87 insertions, 0 deletions
diff --git a/src/bin/zot/command/channel/export.rs b/src/bin/zot/command/channel/export.rs new file mode 100644 index 0000000..ad006de --- /dev/null +++ b/src/bin/zot/command/channel/export.rs @@ -0,0 +1,19 @@ +/* + * SPDX-FileCopyrightText: 2024 Eilertsens Kodeknekkeri + * SPDX-FileCopyrightText: 2024 Harald Eilertsen + * + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +use zotapi::ZotApi; +use std::error::Error; + +pub struct ChannelExportCmd { +} + +impl ChannelExportCmd { + pub async fn run(&self, client: ZotApi) -> Result<(), Box<dyn Error + 'static>> { + println!("{}", client.channel_export().await?); + Ok(()) + } +} diff --git a/src/bin/zot/command/channel/list.rs b/src/bin/zot/command/channel/list.rs new file mode 100644 index 0000000..a308517 --- /dev/null +++ b/src/bin/zot/command/channel/list.rs @@ -0,0 +1,21 @@ +/* + * SPDX-FileCopyrightText: 2024 Eilertsens Kodeknekkeri + * SPDX-FileCopyrightText: 2024 Harald Eilertsen + * + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +use zotapi::ZotApi; +use std::error::Error; + +pub struct ChannelListCmd { +} + +impl ChannelListCmd { + pub async fn run(&self, client: ZotApi) -> Result<(), Box<(dyn Error + 'static)>> { + for ch in client.channel_list().await? { + println!("{}", ch); + } + Ok(()) + } +} diff --git a/src/bin/zot/command/channel/stream.rs b/src/bin/zot/command/channel/stream.rs new file mode 100644 index 0000000..365158b --- /dev/null +++ b/src/bin/zot/command/channel/stream.rs @@ -0,0 +1,47 @@ +/* + * 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(()) + } +} |