From e48434634c3893f1bb39184d105913e86a2408e5 Mon Sep 17 00:00:00 2001 From: Andrew Schofield Date: Wed, 12 Feb 2020 20:03:36 +0000 Subject: [PATCH] Support joint accounts --- Gemfile.lock | 24 +++++++++--------------- lib/qif_creator.rb | 2 +- lib/transaction_fetcher.rb | 4 ++-- monzo-export.rb | 28 ++++++++++++---------------- 4 files changed, 24 insertions(+), 34 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index f5446d5..5001032 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,25 +3,21 @@ GEM specs: classy_struct (0.3.2) colorize (0.8.1) - commander (4.4.0) - highline (~> 1.7.2) - domain_name (0.5.20170404) + commander (4.4.7) + highline (~> 2.0.0) + domain_name (0.5.20180417) unf (>= 0.0.5, < 1.0.0) - ffi (1.9.18-x64-mingw32) - highline (1.7.8) + ffi (1.11.1-x64-mingw32) + highline (2.0.2) http-cookie (1.0.3) domain_name (~> 0.5) - mime-types (3.1) + mime-types (3.2.2) mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) + mime-types-data (3.2019.0331) netrc (0.11.0) omnistruct (1.1.0) classy_struct (~> 0.3, >= 0.3.2) qif (1.2.0) - rest-client (2.0.2) - http-cookie (>= 1.0.2, < 2.0) - mime-types (>= 1.16, < 4.0) - netrc (~> 0.8) rest-client (2.0.2-x64-mingw32) ffi (~> 1.9) http-cookie (>= 1.0.2, < 2.0) @@ -29,11 +25,9 @@ GEM netrc (~> 0.8) unf (0.1.4) unf_ext - unf_ext (0.0.7.4) - unf_ext (0.0.7.4-x64-mingw32) + unf_ext (0.0.7.6) PLATFORMS - ruby x64-mingw32 DEPENDENCIES @@ -44,4 +38,4 @@ DEPENDENCIES rest-client BUNDLED WITH - 1.15.1 + 1.17.2 diff --git a/lib/qif_creator.rb b/lib/qif_creator.rb index 81fcf2a..82de42b 100644 --- a/lib/qif_creator.rb +++ b/lib/qif_creator.rb @@ -52,7 +52,7 @@ def create(path = nil, settled_only: false, account_number: nil) qif << Qif::Transaction.new( date: transaction.created, amount: transaction.amount.to_f / 100, - memo: memo, + memo: transaction.description, payee: (transaction.merchant ? transaction.merchant.name : nil) || (transaction.is_load ? 'Topup' : 'Unknown') ) diff --git a/lib/transaction_fetcher.rb b/lib/transaction_fetcher.rb index 54b045b..cb49196 100644 --- a/lib/transaction_fetcher.rb +++ b/lib/transaction_fetcher.rb @@ -4,9 +4,9 @@ require 'rest-client' class TransactionFetcher - def initialize(access_token, current_account: false) + def initialize(access_token, joint_account: false) @access_token = access_token - @account_type = current_account ? "uk_retail" : "uk_prepaid" + @account_type = joint_account ? "uk_retail_joint" : "uk_retail" @account = http_get("/accounts?account_type=#{@account_type}")['accounts'].first @account_id = @account['id'] end diff --git a/monzo-export.rb b/monzo-export.rb index 7b7d630..fbc9571 100755 --- a/monzo-export.rb +++ b/monzo-export.rb @@ -19,19 +19,17 @@ c.option '--since DATE', String, 'The date (YYYY-MM-DD) to start exporting transactions from. Defaults to 2 weeks ago' c.option '--folder PATH', String, 'The folder to export to. Defaults to ./exports' c.option '--settled_only', String, 'Only export settled transactions' - c.option '--prepaid_account', String, 'Export transactions from the prepaid account instead of any current accounts' + c.option '--joint_account', String, 'Export transactions from the joint account instead of any personal accounts' c.option '--config_file FILE', String, 'Optional config filename' c.action do |args, options| since = options.since ? Date.parse(options.since).to_time : (Time.now - (60*60*24*14)).to_date config = options.config_file ? options.config_file : 'config.yml' access_token = options.access_token || OAuth.new(config).getAccessToken - fetcher = TransactionFetcher.new(access_token, current_account: !options.prepaid_account) - QifCreator.new(fetcher.fetch(since: since)).create(options.folder, settled_only: options.settled_only, account_number: (fetcher.account_number || 'prepaid')) + fetcher = TransactionFetcher.new(access_token, joint_account: options.joint_account) + QifCreator.new(fetcher.fetch(since: since)).create(options.folder, settled_only: options.settled_only, account_number: fetcher.account_number) - if options.current_account - say "Account Number: #{fetcher.account_number}" - say "Sort Code: #{fetcher.sort_code}" - end + say "Account Number: #{fetcher.account_number}" + say "Sort Code: #{fetcher.sort_code}" say "Balance: £#{fetcher.balance}" end @@ -41,17 +39,15 @@ c.syntax = 'monzo-export balance [options]' c.summary = 'Show the balance' c.option '--access_token TOKEN', String, 'Your access token from: https://developers.monzo.com/' - c.option '--prepaid_account', String, 'Export transactions from the prepaid account instead of any current accounts' + c.option '--joint_account', String, 'Export transactions from the joint account instead of any personal accounts' c.option '--config_file FILE', String, 'Optional config filename' c.action do |args, options| config = options.config_file ? options.config_file : 'config.yml' access_token = options.access_token || OAuth.new(config).getAccessToken - fetcher = TransactionFetcher.new(access_token, current_account: !options.prepaid_account) + fetcher = TransactionFetcher.new(access_token, joint_account: options.joint_account) - if options.current_account - say "Account Number: #{fetcher.account_number}" - say "Sort Code: #{fetcher.sort_code}" - end + say "Account Number: #{fetcher.account_number}" + say "Sort Code: #{fetcher.sort_code}" say "Balance: £#{fetcher.balance}" end @@ -64,14 +60,14 @@ c.option '--since DATE', String, 'The date (YYYY-MM-DD) to start exporting transactions from. Defaults to 2 weeks ago' c.option '--folder PATH', String, 'The folder to export to. Defaults to ./exports' c.option '--settled_only', String, 'Only export settled transactions' - c.option '--prepaid_account', String, 'Export transactions from the prepaid account instead of any current accounts' + c.option '--joint_account', String, 'Export transactions from the joint account instead of any personal accounts' c.option '--config_file FILE', String, 'Optional config filename' c.action do |args, options| since = options.since ? Date.parse(options.since).to_time : (Time.now - (60*60*24*14)).to_date config = options.config_file ? options.config_file : 'config.yml' access_token = options.access_token || OAuth.new(config).getAccessToken - fetcher = TransactionFetcher.new(access_token, current_account: !options.prepaid_account) - CsvCreator.new(fetcher.fetch(since: since)).create(options.folder, settled_only: options.settled_only, account_number: (fetcher.account_number || 'prepaid')) + fetcher = TransactionFetcher.new(access_token, joint_account: options.joint_account) + CsvCreator.new(fetcher.fetch(since: since)).create(options.folder, settled_only: options.settled_only, account_number: fetcher.account_number) end end