monese_csv_downloader 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b89c78c67578ad4d216521c68aad1c9e426f43e31426018bb6bf9f0b6768a4b1
4
+ data.tar.gz: ff41c8f725ec984d1a1d5113a23316b0b82ae6891a73691f00e8a5e73d9bab53
5
+ SHA512:
6
+ metadata.gz: 1b12c2c76fd0be320bf1c3017c6fe7ea6e8cb5c1cfc2e1d98314be2f2fe24c7272071aebcb61db321028c0d13981237c02f333942c5bebd5360b22857599638d
7
+ data.tar.gz: 9bc733563569f2e27961d1ecfdde9a76256f8561987dc188c3f6092b79dbf338c12c460db0e080da4dceccbb4aeb417a31f91138845ae3f83908cdb8556f60a5
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.8
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in monese_csv_downloader.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ monese_csv_downloader (0.1.0)
5
+ thor (~> 1.1)
6
+ watir (~> 6.19)
7
+ webdrivers (~> 4.5.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ childprocess (3.0.0)
13
+ mini_portile2 (2.5.1)
14
+ minitest (5.14.4)
15
+ nokogiri (1.11.4)
16
+ mini_portile2 (~> 2.5.0)
17
+ racc (~> 1.4)
18
+ racc (1.5.2)
19
+ rake (10.5.0)
20
+ regexp_parser (2.1.1)
21
+ rubyzip (2.3.0)
22
+ selenium-webdriver (3.142.7)
23
+ childprocess (>= 0.5, < 4.0)
24
+ rubyzip (>= 1.2.2)
25
+ thor (1.1.0)
26
+ watir (6.19.1)
27
+ regexp_parser (>= 1.2, < 3)
28
+ selenium-webdriver (>= 3.142.7)
29
+ webdrivers (4.5.0)
30
+ nokogiri (~> 1.6)
31
+ rubyzip (>= 1.3.0)
32
+ selenium-webdriver (>= 3.0, < 4.0)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ bundler (~> 2.0)
39
+ minitest (~> 5.0)
40
+ monese_csv_downloader!
41
+ rake (~> 10.0)
42
+
43
+ BUNDLED WITH
44
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Paul Kuruvilla
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.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # MoneseCsvDownloader
2
+
3
+ Downloads account statement CSVs from [Monese](https://monese.com/gb/en) using the web interface.
4
+
5
+ **Limitations**:
6
+
7
+ I created this for personal use, so some of the functionality is hard-coded to target my use-case. I'm open to
8
+ contributions that help make this more generic:
9
+
10
+ - Hard-coded to select the first Monese joint account available
11
+ - Hard-coded to download CSV statement for the past 3 months
12
+ - Hard-coded to only support UK numbers (+44-xxxxxxxxxx)
13
+
14
+ ## Installation
15
+
16
+ ```
17
+ gem install monese_csv_downloader
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```sh
23
+ monese_csv_downloader --phone-number "+44-1234567890" --password "dummy_password" download statement.csv
24
+ ```
25
+
26
+ ## Development
27
+
28
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
29
+ also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
32
+ version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
33
+ push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rohitpaulk/monese_csv_downloader.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ require "webdrivers"
4
+ load 'webdrivers/Rakefile'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "monese_csv_downloader"
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__)
data/bin/setup ADDED
@@ -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,3 @@
1
+ #!/usr/bin/env ruby
2
+ require "monese_csv_downloader/cli"
3
+ MoneseCsvDownloader::CLI.start
@@ -0,0 +1,15 @@
1
+ require "monese_csv_downloader/version"
2
+
3
+ module MoneseCsvDownloader
4
+ class Error < StandardError; end
5
+ # Your code goes here...
6
+
7
+ def new(monese_username:, monese_password:)
8
+ @monese_username = monese_username
9
+ @monese_password = monese_password
10
+ end
11
+
12
+ def download
13
+ @monese_username
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ require "thor"
2
+ require_relative "./web_client"
3
+
4
+ module MoneseCsvDownloader
5
+ class CLI < Thor
6
+ def self.exit_on_failure?
7
+ true
8
+ end
9
+
10
+ desc "download FILE", "Downloads an account statement to FILE"
11
+ method_option :phone_number, desc: "Phone number for Monese account", required: true
12
+ method_option :password, desc: "Password for Monese account", required: true
13
+ def download(file)
14
+ puts "downloading to #{file}"
15
+ contents = MoneseCsvDownloader::WebClient.new(options.fetch(:phone_number), options.fetch(:password)).download
16
+ File.write(file, contents)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module MoneseCsvDownloader
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,76 @@
1
+ require "tmpdir"
2
+
3
+ require "watir"
4
+
5
+ module MoneseCsvDownloader
6
+ class WebClient
7
+ def initialize(monese_account_phone_number, monese_account_password)
8
+ @monese_account_phone_number = monese_account_phone_number
9
+ @monese_account_password = monese_account_password
10
+ end
11
+
12
+ def browser
13
+ sleep(1) # Act like a human
14
+ @browser ||= self.firefox_browser
15
+ end
16
+
17
+ def downloaded_file
18
+ File.join(self.temporary_directory, (Dir.entries(self.temporary_directory) - [".", ".."]).first)
19
+ end
20
+
21
+ def temporary_directory
22
+ @temporary_directory ||= Dir.mktmpdir
23
+ end
24
+
25
+ # Unused, I wasn't able to get downloads to a specific path working with this.
26
+ def chrome_browser
27
+ chrome_prefs = {
28
+ :download => {
29
+ :prompt_for_download => false,
30
+ :directory_upgrade => true,
31
+ :default_directory => "/tmp/chrome_downloads"
32
+ },
33
+ :savefile => {
34
+ :default_directory => "/tmp/chrome_downloads"
35
+ },
36
+ :profile => {
37
+ default_content_settings: { popups: 0 }
38
+ }
39
+ }
40
+
41
+ Watir::Browser.new :chrome, options: { prefs: chrome_prefs }
42
+ end
43
+
44
+ def firefox_browser
45
+ profile = Selenium::WebDriver::Firefox::Profile.new
46
+ profile['browser.download.folderList'] = 2 # custom location
47
+ profile['browser.download.dir'] = self.temporary_directory
48
+ profile['browser.helperApps.neverAsk.saveToDisk'] = 'text/csv,application/pdf'
49
+
50
+ Watir::Browser.new :firefox, options: { profile: profile }
51
+ end
52
+
53
+ def download
54
+ # Login
55
+ self.browser.goto "https://web.monese.com/"
56
+ self.browser.text_field(data_testid: "login-input").set @monese_account_phone_number[4..-1]
57
+ self.browser.button(data_testid: "login-submit-button").click
58
+ self.browser.text_field(data_testid: "input-password").set @monese_account_password
59
+ self.browser.button(data_testid: "form-submit").click
60
+
61
+ # Select joint account
62
+ self.browser.a(data_testid: "account-link-1-MONESE_JOINT").click
63
+
64
+ self.browser.button(data_testid: "download-statement-button").click
65
+ self.browser.div(class: /DownloadModal-module__InputWrapper/, index: 1).click
66
+ self.browser.button(data_testid: "csv").click
67
+ self.browser.button(text: /Download/).click
68
+
69
+ sleep 10 # Wait for file download to complete
70
+
71
+ self.browser.close
72
+
73
+ File.read(self.downloaded_file)
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,39 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "monese_csv_downloader/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "monese_csv_downloader"
7
+ spec.version = MoneseCsvDownloader::VERSION
8
+ spec.authors = ["Paul Kuruvilla"]
9
+ spec.email = ["rohitpaulk@gmail.com"]
10
+
11
+ spec.summary = "Download CSV account statements from Monese"
12
+ spec.description = "Uses chrome-webdriver to download account statements from the Monese web interface"
13
+ spec.homepage = "https://github.com/rohitpaulk/monese_csv_downloader"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ spec.metadata["allowed_push_host"] = "https://rubygems.org/"
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/rohitpaulk/monese_csv_downloader"
21
+ spec.metadata["changelog_uri"] = "https://github.com/rohitpaulk/monese_csv_downloader/blob/master/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 2.0"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "minitest", "~> 5.0"
35
+
36
+ spec.add_runtime_dependency "thor", "~> 1.1"
37
+ spec.add_runtime_dependency "watir", "~> 6.19"
38
+ spec.add_runtime_dependency "webdrivers", "~> 4.5.0"
39
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: monese_csv_downloader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul Kuruvilla
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-05-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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: watir
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '6.19'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '6.19'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webdrivers
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 4.5.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 4.5.0
97
+ description: Uses chrome-webdriver to download account statements from the Monese
98
+ web interface
99
+ email:
100
+ - rohitpaulk@gmail.com
101
+ executables:
102
+ - monese_csv_downloader
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - exe/monese_csv_downloader
116
+ - lib/monese_csv_downloader.rb
117
+ - lib/monese_csv_downloader/cli.rb
118
+ - lib/monese_csv_downloader/version.rb
119
+ - lib/monese_csv_downloader/web_client.rb
120
+ - monese_csv_downloader.gemspec
121
+ homepage: https://github.com/rohitpaulk/monese_csv_downloader
122
+ licenses:
123
+ - MIT
124
+ metadata:
125
+ allowed_push_host: https://rubygems.org/
126
+ homepage_uri: https://github.com/rohitpaulk/monese_csv_downloader
127
+ source_code_uri: https://github.com/rohitpaulk/monese_csv_downloader
128
+ changelog_uri: https://github.com/rohitpaulk/monese_csv_downloader/blob/master/CHANGELOG.md
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.7.6.2
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Download CSV account statements from Monese
149
+ test_files: []