monzo2qif 0.1.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9026e210b2e4740443015ded3b9223ee409c9530
4
+ data.tar.gz: 7c822a6e5d26ffc59fea32f24525c22749976ba7
5
+ SHA512:
6
+ metadata.gz: a8435cff689ab936fe6410b6ac716249741e9ff5189592300adf67bb1c0ebf597249953b85e8b1376bae799e49cbef7284d18a3418ee4d1b30b57ef080a63ad3
7
+ data.tar.gz: 48331c1a674e1de827a75e97e83e6f3324b199672f3e86dc1180e1a7d2e37dc206d70c1a113e2afca2c4aa5e15717215f5b0c5e0890167bbe469b626e064c983
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,8 @@
1
+ inherit_from:
2
+ - .rubocop_todo.yml
3
+
4
+ Documentation:
5
+ Enabled: false
6
+
7
+ Style/HashSyntax:
8
+ EnforcedStyle: ruby19_no_mixed_keys
@@ -0,0 +1,16 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2017-04-16 21:25:37 +0100 using RuboCop version 0.47.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ Metrics/AbcSize:
11
+ Max: 16
12
+
13
+ # Offense count: 1
14
+ # Configuration parameters: CountComments.
15
+ Metrics/MethodLength:
16
+ Max: 16
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in monzo2qif.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Jim Myhrberg
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,50 @@
1
+ # Monzo2QIF
2
+
3
+ Super-hacky and quickly thrown together Monzo to QIF exporter. Use at your own
4
+ risk.
5
+
6
+ I've put bare minimum amount of work needed into this project just to get it
7
+ working in a way that it does exactly what I want, and nothing more. This is
8
+ essentially experimental pre-alpha code.
9
+
10
+ The reason I rolled my own instead of using one of the existing Monzo QIF export
11
+ projects floating around on GitHub, is cause requirements were simpler:
12
+
13
+ - Set `payee` value based on Monzo transaction `description`. Meaning merchant
14
+ info from Monzo is completely ignored.
15
+ - Set `memo` value based on Monzo transaction `notes`, nothing else. Other Monzo
16
+ QIF export projects use the `memo` QIF field to add various pieces of extra
17
+ info and metadata from Monzo. I don't care for it. But I do care for any
18
+ custom notes I've manually added to a transaction in Monzo.
19
+
20
+ ## Installation
21
+
22
+ ```
23
+ gem install monzo2qif --pre
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ```
29
+ Usage: monzo2qif [options]
30
+
31
+ Options:
32
+ -t, --token=<s> Monzo account token - https://developers.monzo.com/
33
+ -u, --include-unsettled Include unsettled transactions?
34
+ -s, --start-date=<s> Start date (optional)
35
+ -e, --end-date=<s> End date (optional)
36
+ -o, --output-dir=<s> Output directory (defaults to current working directory)
37
+
38
+ -v, --version Print version and exit
39
+ -h, --help Show this message
40
+ ```
41
+
42
+ ## Todo
43
+
44
+ - Abandon this project if the official Monzo app for Android ever gets QIF
45
+ export support.
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of
50
+ the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'monzo2qif'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.expand_path('../../lib', File.realpath(__FILE__)))
3
+ require 'monzo2qif'
4
+
5
+ Monzo2QIF::CLI.run(ARGV)
@@ -0,0 +1,5 @@
1
+ require 'monzo2qif/cli'
2
+
3
+ module Monzo2QIF
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,67 @@
1
+ require 'active_support/core_ext/time/calculations'
2
+ require 'trollop'
3
+
4
+ require 'monzo2qif/runner'
5
+ require 'monzo2qif/version'
6
+
7
+ module Monzo2QIF
8
+ class CLI
9
+ attr_reader :options
10
+
11
+ def self.run(args = [])
12
+ new(args).run
13
+ end
14
+
15
+ def initialize(args)
16
+ @options = parse_args(args)
17
+ end
18
+
19
+ def run
20
+ runner = Runner.new(options)
21
+ runner.run
22
+ end
23
+
24
+ private
25
+
26
+ def parse_args(args)
27
+ opts = Trollop.with_standard_exception_handling(parser) do
28
+ parser.parse(args.clone)
29
+ end
30
+
31
+ if opts[:start_date]
32
+ opts[:start_date] = Time.parse(opts[:start_date]).beginning_of_day
33
+ end
34
+
35
+ if opts[:end_date]
36
+ opts[:end_date] = Time.parse(opts[:end_date]).end_of_day
37
+ end
38
+
39
+ opts
40
+ end
41
+
42
+ def parser
43
+ @parser ||= begin
44
+ parser = Trollop::Parser.new
45
+ parser.banner 'Usage: monzo2qif [options]'
46
+ parser.version "monzo2qif #{VERSION}"
47
+
48
+ define_options(parser)
49
+ parser.banner ''
50
+ parser
51
+ end
52
+ end
53
+
54
+ def define_options(parser)
55
+ parser.banner "\nOptions:"
56
+ parser.opt :token, 'Monzo account token - https://developers.monzo.com/',
57
+ short: 't', type: :string, required: true
58
+ parser.opt :include_unsettled, 'Include unsettled transactions',
59
+ short: 'u', type: :bool
60
+ parser.opt :start_date, 'Start date (optional)', short: 's', type: :string
61
+ parser.opt :end_date, 'End date (optional)', short: 'e', type: :string
62
+ parser.opt :output_dir,
63
+ 'Output directory (defaults to current working directory)',
64
+ short: 'o', type: :string
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,91 @@
1
+ require 'mondo'
2
+
3
+ require 'monzo2qif/transaction'
4
+
5
+ module Monzo2QIF
6
+ class Runner
7
+ attr_reader :token
8
+ attr_reader :start_date
9
+ attr_reader :end_date
10
+ attr_reader :output_dir
11
+ attr_reader :include_unsettled
12
+
13
+ DATE_FORMAT = '%Y-%m-%d'.freeze
14
+
15
+ def initialize(options)
16
+ @token = options[:token]
17
+ @start_date = options[:start_date]
18
+ @end_date = options[:end_date]
19
+ @output_dir = options[:output_dir]
20
+ @include_unsettled = options[:include_unsettled]
21
+ end
22
+
23
+ def run
24
+ count = 0
25
+ Qif::Writer.open(filepath, 'Bank', 'dd/mm/yyyy') do |qif|
26
+ transactions.each do |t|
27
+ if t.declined?
28
+ puts "Skipping declined: #{t}"
29
+ next
30
+ end
31
+
32
+ if !include_unsettled && !t.settled?
33
+ puts "Skipping unsettled: #{t}"
34
+ next
35
+ end
36
+
37
+ count += 1
38
+ qif << t.to_qif
39
+ end
40
+ end
41
+
42
+ puts "Exported #{count} transactions to #{filepath}"
43
+ end
44
+
45
+ private
46
+
47
+ def filepath
48
+ dir = File.expand_path(output_dir || Dir.pwd)
49
+ File.join(dir, filename)
50
+ end
51
+
52
+ def filename
53
+ "#{account_name} (#{filename_start_date} - #{filename_end_date}).qif"
54
+ end
55
+
56
+ def filename_start_date
57
+ time = start_date || transactions.last.date
58
+ time.strftime(DATE_FORMAT)
59
+ end
60
+
61
+ def filename_end_date
62
+ time = end_date || transactions.first.date
63
+ time.strftime(DATE_FORMAT)
64
+ end
65
+
66
+ def account_name
67
+ @account_name ||= account.description
68
+ end
69
+
70
+ def account
71
+ @account ||= client.accounts.first
72
+ end
73
+
74
+ def transactions
75
+ @transactions ||= client.transactions(transactions_opts)
76
+ .map { |t| Transaction.new(t) }
77
+ .sort_by(&:date).reverse
78
+ end
79
+
80
+ def transactions_opts
81
+ opts = {}
82
+ opts[:since] = start_date.iso8601 if start_date
83
+ opts[:before] = end_date.iso8601 if end_date
84
+ opts
85
+ end
86
+
87
+ def client
88
+ @client ||= Mondo::Client.new(token: token)
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,57 @@
1
+ require 'active_support/core_ext/object/blank'
2
+ require 'qif'
3
+
4
+ module Monzo2QIF
5
+ class Transaction
6
+ attr_reader :source
7
+
8
+ def initialize(monzo_transaction)
9
+ @source = monzo_transaction
10
+ end
11
+
12
+ def declined?
13
+ source.declined?
14
+ end
15
+
16
+ def settled?
17
+ source.settled.present?
18
+ end
19
+
20
+ def to_qif
21
+ Qif::Transaction.new(qif_attributes)
22
+ end
23
+
24
+ def to_s
25
+ "#<#{self.class} #{qif_attributes}>"
26
+ end
27
+
28
+ def date
29
+ source.created
30
+ end
31
+
32
+ def payee
33
+ source.description
34
+ end
35
+
36
+ def amount
37
+ source.amount.to_f
38
+ end
39
+
40
+ def memo
41
+ source.notes unless source.notes == ''
42
+ end
43
+
44
+ private
45
+
46
+ def qif_attributes
47
+ attrs = {
48
+ date: date,
49
+ amount: amount,
50
+ payee: payee
51
+ }
52
+
53
+ attrs[:memo] = memo if memo
54
+ attrs
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module Monzo2QIF
2
+ VERSION = '0.1.0.alpha1'.freeze
3
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'monzo2qif/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'monzo2qif'
8
+ spec.version = Monzo2QIF::VERSION
9
+ spec.authors = ['Jim Myhrberg']
10
+ spec.email = ['contact@jimeh.me']
11
+
12
+ spec.summary = 'Super-hacky and quickly thrown together Monzo to ' \
13
+ 'QIF exporter'
14
+ spec.description = 'Super-hacky and quickly thrown together Monzo to ' \
15
+ 'QIF exporter'
16
+ spec.homepage = 'https://github.com/jimeh/monzo2qif'
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.14'
27
+ spec.add_development_dependency 'byebug'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ spec.add_development_dependency 'rubocop', '~> 0.47.1'
31
+
32
+ spec.add_runtime_dependency 'activesupport', '~> 5.0.2' # required by mondo
33
+ spec.add_runtime_dependency 'mondo', '~> 0.5.0'
34
+ spec.add_runtime_dependency 'qif', '~> 1.2.0'
35
+ spec.add_runtime_dependency 'trollop', '~> 2.1.2'
36
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: monzo2qif
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.alpha1
5
+ platform: ruby
6
+ authors:
7
+ - Jim Myhrberg
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.47.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.47.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 5.0.2
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 5.0.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: mondo
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.5.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.5.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: qif
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.2.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.2.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: trollop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 2.1.2
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 2.1.2
139
+ description: Super-hacky and quickly thrown together Monzo to QIF exporter
140
+ email:
141
+ - contact@jimeh.me
142
+ executables:
143
+ - monzo2qif
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".rubocop.yml"
150
+ - ".rubocop_todo.yml"
151
+ - ".travis.yml"
152
+ - Gemfile
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - bin/console
157
+ - bin/setup
158
+ - exe/monzo2qif
159
+ - lib/monzo2qif.rb
160
+ - lib/monzo2qif/cli.rb
161
+ - lib/monzo2qif/runner.rb
162
+ - lib/monzo2qif/transaction.rb
163
+ - lib/monzo2qif/version.rb
164
+ - monzo2qif.gemspec
165
+ homepage: https://github.com/jimeh/monzo2qif
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">"
181
+ - !ruby/object:Gem::Version
182
+ version: 1.3.1
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.6.11
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: Super-hacky and quickly thrown together Monzo to QIF exporter
189
+ test_files: []