aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/zot/command/channel/stream.rs
blob: 365158b1add46f57580027201071ccafd45cfe9e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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(())
    }
}