menthol 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
+ SHA1:
3
+ metadata.gz: 7cb4f160644f6169669c8031f9e8e130ee47a783
4
+ data.tar.gz: d06cd4396e30bb2aa17d85c34c5fa4ba7f5d89bd
5
+ SHA512:
6
+ metadata.gz: cfe2d93ac2dabc40398a19e846800bb92aa3d0ac07a53db15ce123a2460c0e5b4b186cd9da8a756768f5ad97171c2616959ab745eb3b70a3d777f32e1e95d073
7
+ data.tar.gz: ab63cccf40aaaae3722d36e5acb725943102c21e78569b994e1efb7e4d46188956daa65c54e98614b0090bfd3fb82f62da22ae3d57044e880f97a39197b74c95
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in menthol.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Robin Clart
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,40 @@
1
+ # Menthol
2
+
3
+ **Warning**: This project is a work in progress.
4
+
5
+ Menthol is a web scraper that fetch your Thai bank account balances and sum
6
+ them for you in your terminal.
7
+
8
+ Store your configuration under `~/.mentholrc` and run with `exe/mentholrc sync`.
9
+
10
+ Here's a sample `~/.mentholrc` configuration file:
11
+
12
+ - provider: Krungsri
13
+ accounts:
14
+ - name: Savings
15
+ currency: THB
16
+ username: johndoe
17
+ password: 1dk49fncH93JsKKJ8
18
+
19
+ - provider: Local
20
+ name: LH Bank
21
+ accounts:
22
+ - name: Fixed
23
+ amount: 10000000
24
+ currency: THB
25
+
26
+ This library currently support:
27
+
28
+ - Krungsri
29
+ - Bangkokbank
30
+ - Kasikornbank
31
+ - Local (the amount must be given in the configuration file as the
32
+ smallest currency subunit)
33
+
34
+ You'll need to instal the `watir` gem. You'll also need Chrome installed and
35
+ `chrome-webdriver` somewhere on your PATH.
36
+
37
+ TODO:
38
+
39
+ - store accounts in redis
40
+ - add web server to display balances and their history
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "menthol"
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
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
data/exe/menthol ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "menthol"
4
+
5
+ profile = Menthol::Profile.configure(File.expand_path("~/.mentholrc"))
6
+
7
+ case ARGV.first
8
+ when "sync"
9
+ profile.sync_all!
10
+
11
+ profile.providers.each do |provider|
12
+ provider.accounts.each do |account|
13
+ puts ["===", account.provider, "|", account.name, "==="].join(" ")
14
+ puts account.amount.format
15
+ end
16
+ end
17
+
18
+ puts "=== Total ==="
19
+ puts profile.amount.format
20
+ else
21
+ puts "usage: menthold COMMAND"
22
+ end
23
+
24
+ exit 0
@@ -0,0 +1,36 @@
1
+ require "money"
2
+
3
+ module Menthol
4
+ class Account
5
+ def initialize(provider, name, amount, currency)
6
+ @provider = provider
7
+ @name = name
8
+ @currency = Money::Currency.find(currency)
9
+ @amount = Money.new(amount || 0, @currency.iso_code)
10
+ end
11
+
12
+ def self.open(provider, configuration)
13
+ new(
14
+ provider,
15
+ configuration["name"],
16
+ configuration["amount"],
17
+ configuration["currency"]
18
+ )
19
+ end
20
+
21
+ attr_reader :provider
22
+
23
+ attr_reader :name
24
+
25
+ attr_reader :amount
26
+
27
+ attr_reader :currency
28
+
29
+ def parse_amount(raw_amount)
30
+ amount = raw_amount.gsub(/[^\d\.]/, "").to_f
31
+ amount_subunit = amount * @currency.subunit_to_unit
32
+
33
+ @amount = Money.new(amount_subunit, @currency.iso_code)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,34 @@
1
+ require "menthol/provider"
2
+ require "menthol/account"
3
+
4
+ module Menthol
5
+ class Bangkokbank < Provider
6
+ private
7
+
8
+ def login_url
9
+ "https://ibanking.bangkokbank.com/SignOn.aspx"
10
+ end
11
+
12
+ def login
13
+ submit_credentials({
14
+ username: "txtID",
15
+ password: "txtPwd",
16
+ button: browser.input(name: "btnLogOn"),
17
+ })
18
+ end
19
+
20
+ def find_amount(name)
21
+ case name
22
+ when "Savings"
23
+ cell = browser.span(id: "ctl00_ctl00_C_CW_gvDepositAccts_ctl02_lblAcctAvailBal").wait_until_present
24
+ cell.text
25
+ end
26
+ end
27
+
28
+ def logout
29
+ button = browser.link(href: "javascript:IMG2_onclick();")
30
+ button.click
31
+ button.wait_while_present
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,44 @@
1
+ require "menthol/provider"
2
+ require "menthol/account"
3
+
4
+ module Menthol
5
+ class Kasikornbank < Provider
6
+ private
7
+
8
+ def login_url
9
+ "https://online.kasikornbankgroup.com/K-Online/preLogin/popupPreLogin.jsp?lang=en&type="
10
+ end
11
+
12
+ def skip_login_popup
13
+ button = browser.input(css: "div[align=center] input")
14
+ button.wait_until_present
15
+ button.click
16
+ button.wait_while_present
17
+ end
18
+
19
+ def login
20
+ skip_login_popup
21
+ submit_credentials({
22
+ username: "userName",
23
+ password: "password",
24
+ button: browser.image(name: "loginBtn"),
25
+ })
26
+ end
27
+
28
+ def find_amount(name)
29
+ case name
30
+ when "Savings"
31
+ frame = browser.iframe(id: "ssoIFrame1")
32
+ cell = frame.element(class: "inner_table_right").wait_until_present
33
+ cell.text
34
+ end
35
+ end
36
+
37
+ def logout
38
+ button = browser.span(text: "Logout")
39
+ button.click
40
+ browser.alert.ok
41
+ button.wait_while_present
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,36 @@
1
+ require "menthol/provider"
2
+
3
+ module Menthol
4
+ class Krungsri < Provider
5
+ private
6
+
7
+ def login_url
8
+ "https://www.krungsrionline.com/BAY.KOL.WebSite/Common/Login.aspx"
9
+ end
10
+
11
+ def login
12
+ submit_credentials({
13
+ username: "ctl00$cphForLogin$username",
14
+ password: "ctl00$cphForLogin$password",
15
+ button: browser.input(name: "ctl00$cphForLogin$lbtnLoginNew")
16
+ })
17
+ end
18
+
19
+ def find_amount(name)
20
+ case name
21
+ when "Savings"
22
+ cell = browser.div(css: ".myport_table_column_3 .amc")
23
+ cell.text
24
+ when "LTF"
25
+ cell = browser.div(css: ".myport_table_column_3_4 .amc")
26
+ cell.text
27
+ end
28
+ end
29
+
30
+ def logout
31
+ button = browser.link(class: "header_logout menu_link_progress")
32
+ button.click
33
+ button.wait_while_present
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,9 @@
1
+ require "menthol/provider"
2
+
3
+ module Menthol
4
+ class Local < Provider
5
+ def sync!
6
+ # void
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,35 @@
1
+ require "yaml"
2
+ require "money"
3
+
4
+ module Menthol
5
+ class Profile
6
+ def initialize(providers)
7
+ @providers = providers
8
+ end
9
+
10
+ attr_reader :providers
11
+
12
+ def self.configure(config_file_path)
13
+ configuration = YAML.load(File.read(config_file_path))
14
+
15
+ providers = configuration.map do |c|
16
+ Menthol.const_get(c["provider"]).new(
17
+ c["name"],
18
+ c["username"],
19
+ c["password"],
20
+ c["accounts"]
21
+ )
22
+ end
23
+
24
+ new(providers)
25
+ end
26
+
27
+ def sync_all!
28
+ @providers.each(&:sync!)
29
+ end
30
+
31
+ def amount
32
+ @providers.map(&:amount).reduce(Money.new(0, "THB"), &:+)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,61 @@
1
+ require "money"
2
+ require "menthol/provider"
3
+
4
+ module Menthol
5
+ class Provider
6
+ def initialize(name, username, password, accounts)
7
+ @name = name
8
+ @username = username
9
+ @password = password
10
+ @accounts = accounts.map { |a| Account.open(self.name, a) }
11
+ end
12
+
13
+ attr_reader :accounts
14
+
15
+ def name
16
+ @name || self.class.name.split("::").last
17
+ end
18
+
19
+ def amount
20
+ @accounts.map(&:amount).reduce(Money.new(0, "THB"), &:+)
21
+ end
22
+
23
+ def sync!
24
+ browser.goto(login_url)
25
+
26
+ login
27
+ synchronize_accounts
28
+ logout
29
+
30
+ browser.quit
31
+ @browser = nil
32
+ end
33
+
34
+ private
35
+
36
+ def submit_credentials(username:, password:, button:)
37
+ browser.text_field(name: username).set(@username)
38
+ browser.text_field(name: password).set(@password)
39
+ button.click
40
+ button.wait_while_present
41
+ end
42
+
43
+ def browser
44
+ @browser ||= Watir::Browser.new(:chrome)
45
+ end
46
+
47
+ def login
48
+ raise NotImplementedError
49
+ end
50
+
51
+ def synchronize_accounts
52
+ @accounts.each do |account|
53
+ account.parse_amount(find_amount(account.name))
54
+ end
55
+ end
56
+
57
+ def logout
58
+ raise NotImplementedError
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module Menthol
2
+ VERSION = "0.1.0"
3
+ end
data/lib/menthol.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "watir"
2
+ require "money"
3
+
4
+ I18n.config.available_locales = :en
5
+
6
+ require "menthol/account"
7
+ require "menthol/profile"
8
+
9
+ require "menthol/local"
10
+ require "menthol/bangkokbank"
11
+ require "menthol/kasikornbank"
12
+ require "menthol/krungsri"
13
+
14
+ module Menthol
15
+ end
data/menthol.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'menthol/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "menthol"
8
+ spec.version = Menthol::VERSION
9
+ spec.authors = ["Robin Clart"]
10
+ spec.email = ["robin@clart.be"]
11
+
12
+ spec.summary = %q{Thai bank accounts balance scraper}
13
+ spec.homepage = "https://github.com/robinclart/menthol"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "watir"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.13"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest", "~> 5.0"
28
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: menthol
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Robin Clart
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: watir
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
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: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description:
70
+ email:
71
+ - robin@clart.be
72
+ executables:
73
+ - menthol
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - exe/menthol
86
+ - lib/menthol.rb
87
+ - lib/menthol/account.rb
88
+ - lib/menthol/bangkokbank.rb
89
+ - lib/menthol/kasikornbank.rb
90
+ - lib/menthol/krungsri.rb
91
+ - lib/menthol/local.rb
92
+ - lib/menthol/profile.rb
93
+ - lib/menthol/provider.rb
94
+ - lib/menthol/version.rb
95
+ - menthol.gemspec
96
+ homepage: https://github.com/robinclart/menthol
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.5.1
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Thai bank accounts balance scraper
120
+ test_files: []