diff --git a/src/main.rs b/src/main.rs index 324c5e8..87fbffe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,28 +29,30 @@ struct Page<'a> { struct Config { #[arg(required = true)] date: String, - #[arg(short)] + #[arg(short, long)] verbose: bool, } #[tokio::main] async fn main() -> Result<()> { - env_logger::init(); let Config { date, verbose } = Config::parse(); if verbose { env::set_var("RUST_LOG", format!("{}=debug", module_path!())); } else { env::set_var("RUST_LOG", format!("{}=none", module_path!())); } + env_logger::init(); let day = try_create_range(date)?; debug!("Date {}", day.end.format("%Y-%m-%d")); let client = create_client()?; + let Response { json: account, .. } = client.verify_account_credentials().await?; let mut last_id_on_page: Option = None; debug!("Fetching posts"); + let mut reversed = Vec::new(); loop { let json = fetch_page(&client, &last_id_on_page).await?; let page = Page { @@ -72,35 +74,51 @@ async fn main() -> Result<()> { let json = json .clone() .into_iter() - .filter(|json| day.start <= json.created_at && json.created_at <= day.end) + .filter(|json| { + json.account.id == account.id + && day.start <= json.created_at + && json.created_at <= day.end + }) .collect::>(); trace!("Filtered to {} post(s)", json.len()); let mut stream = iter(json); while let Some(status) = stream.next().await { - println!( + let ancestor = format!( "{} > {}", status.created_at.with_timezone(&Local).format("%H:%M"), - parse_html(&status.content) + parse_html(&status.content).trim() ); let Response { json, .. } = client.get_status_context(status.id, None).await?; let thread = json .descendants .into_iter() + .filter(|s| { + s.in_reply_to_account_id == Some(account.id.clone()) + && s.account.id == account.id + }) .map(|status| { format!( "> > {} >> {}", status.created_at.with_timezone(&Local).format("%H:%M"), - parse_html(&status.content) + parse_html(&status.content).trim() ) }) .collect::>() .join("\n"); - println!("{}", thread); + reversed.push(format!( + "{}{}", + ancestor, + if !thread.is_empty() { + thread + } else { + String::default() + } + )); } if page_end_older_than(&page, &day) { @@ -112,6 +130,8 @@ async fn main() -> Result<()> { last_id_on_page.replace(id.clone()); } } + reversed.reverse(); + println!("{}", reversed.join("\n\n")); Ok(()) }