From f3f1578ca86227f87138bc0728a2f2b10aa29ca0 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 25 Aug 2019 14:49:16 -0400 Subject: also load scheduled transactions --- src/main.rs | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 85623cb..3108ebb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,7 @@ pub fn read_api_key() -> String { key.to_string() } +#[allow(clippy::cognitive_complexity)] fn main() { let key = read_api_key(); let mut ynab_config = ynab_api::apis::configuration::Configuration::new(); @@ -255,4 +256,78 @@ fn main() { } file.sync_all().unwrap(); file2.sync_all().unwrap(); + + let mut file = + std::fs::File::create("scheduled_transactions.tsv").unwrap(); + for scheduled_transaction in budget.scheduled_transactions.unwrap() { + if scheduled_transaction.deleted { + continue; + } + file.write_all( + [ + scheduled_transaction.id.as_ref(), + scheduled_transaction.date_next.as_ref(), + scheduled_transaction.frequency.as_ref(), + format!("{}", scheduled_transaction.amount).as_ref(), + scheduled_transaction + .memo + .unwrap_or_else(|| "\\N".to_string()) + .as_ref(), + scheduled_transaction.flag_color.as_ref(), + scheduled_transaction.account_id.as_ref(), + scheduled_transaction + .payee_id + .unwrap_or_else(|| "\\N".to_string()) + .as_ref(), + if scheduled_transaction.category_id == SPLIT_CATEGORY_ID { + "\\N" + } else { + scheduled_transaction.category_id.as_ref() + }, + scheduled_transaction + .transfer_account_id + .unwrap_or_else(|| "\\N".to_string()) + .as_ref(), + ] + .join("\t") + .as_bytes(), + ) + .unwrap(); + file.write_all(b"\n").unwrap(); + } + file.sync_all().unwrap(); + + let mut file = + std::fs::File::create("scheduled_subtransactions.tsv").unwrap(); + for scheduled_subtransaction in budget.scheduled_subtransactions.unwrap() + { + if scheduled_subtransaction.deleted { + continue; + } + file.write_all( + [ + scheduled_subtransaction.id.as_ref(), + scheduled_subtransaction.scheduled_transaction_id.as_ref(), + format!("{}", scheduled_subtransaction.amount).as_ref(), + scheduled_subtransaction + .memo + .unwrap_or_else(|| "\\N".to_string()) + .as_ref(), + scheduled_subtransaction + .payee_id + .unwrap_or_else(|| "\\N".to_string()) + .as_ref(), + scheduled_subtransaction.category_id.as_ref(), + scheduled_subtransaction + .transfer_account_id + .unwrap_or_else(|| "\\N".to_string()) + .as_ref(), + ] + .join("\t") + .as_bytes(), + ) + .unwrap(); + file.write_all(b"\n").unwrap(); + } + file.sync_all().unwrap(); } -- cgit v1.2.3-54-g00ecf