bunq-rs/examples/download_statement.rs
Jacob Kiers 5a9da2d29a Support downloading account statements
As described in the examples/download_statement.rs file.

Signed-off-by: Jacob Kiers <code@kiers.eu>
2024-03-01 07:09:28 +01:00

36 lines
851 B
Rust

use anyhow::Result;
use bunq::{BunqConfig, CsvType, StatementFormat};
use std::time::Duration;
fn main() -> Result<()> {
let cfg = BunqConfig::load()?;
let client = cfg.install()?;
let accs = client.monetary_accounts()?;
let acc = &accs[0];
let stmt_id = client.request_statement(
acc,
StatementFormat::CSV(CsvType::Semicolon),
"2023-12-05",
"2023-12-15",
)?;
println!("Waiting for statement {:?}...", stmt_id);
let mut ready = client.is_statement_ready(acc, stmt_id)?;
while !ready {
println!("Statement is not ready yet. Waiting 5 seconds...");
std::thread::sleep(Duration::from_secs(5));
ready = client.is_statement_ready(acc, stmt_id)?;
}
let contents = client.download_statement(acc, stmt_id)?;
println!("{contents}");
Ok(())
}