Skip to main content

catalog_images/
catalog_images.rs

1//! cargo run --example catalog_images -- po
2//! Walks a board's catalog and prints every image URL.
3
4use std::env;
5
6#[chan::tokio::main]
7async fn main() -> chan::Result<()> {
8    let board = env::args().nth(1).unwrap_or_else(|| "po".to_string());
9    let client = chan::Client::new();
10    let catalog = client.get_board_catalog(&board).await?;
11
12    let mut count = 0usize;
13    for thread in catalog.threads() {
14        if let Some(att) = &thread.op.attachment {
15            if !att.is_animated() {
16                println!("{}", att.url(&board));
17                count += 1;
18            }
19        }
20        for reply in &thread.last_replies {
21            if let Some(att) = &reply.attachment {
22                if !att.is_animated() {
23                    println!("{}", att.url(&board));
24                    count += 1;
25                }
26            }
27        }
28    }
29    eprintln!("/{}/: {} still-image URLs", board, count);
30    Ok(())
31}