Support downloading account statements
As described in the examples/download_statement.rs file. Signed-off-by: Jacob Kiers <code@kiers.eu>
This commit is contained in:
35
examples/download_statement.rs
Normal file
35
examples/download_statement.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
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(())
|
||||
}
|
Reference in New Issue
Block a user