bankscrap 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -3
- data/lib/bankscrap/cli.rb +33 -10
- data/lib/bankscrap/exporters/csv.rb +20 -0
- data/lib/bankscrap/transaction.rb +4 -0
- data/lib/bankscrap/version.rb +1 -1
- data/lib/bankscrap.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2142881eec4c8dcc412763eb07d3c84cc33d1fe
|
4
|
+
data.tar.gz: a23a8c1e02e54605ca8789a601f7774eb5712bca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c5a268c46975640c1d851fc860d863f6bbcba8450d0992ec6f23a4f62b6973fe8734ac05169593bfa5ef9d7d15bd3787dc4feb5d7ec8f534453052a54ce5684
|
7
|
+
data.tar.gz: e8dbc234ed3712d90e6b0bbecbb4fe40373de20b17416a5ba040424e1791a421413f4139d46ae6ccc8cde9e989b0ea9cc2b0d643b37ff1f2b56055ed65ef312c
|
data/README.md
CHANGED
@@ -77,29 +77,37 @@ Replace 01/01/1980 with your actual birthday.
|
|
77
77
|
|
78
78
|
#### Transactions with date range
|
79
79
|
|
80
|
-
$ bankscrap transactions YourBank --user YOUR_BANK_USER --password YOUR_BANK_PASSWORD --
|
80
|
+
$ bankscrap transactions YourBank --user YOUR_BANK_USER --password YOUR_BANK_PASSWORD --from 01-01-2015 --to 01-02-2015
|
81
81
|
|
82
82
|
---
|
83
83
|
|
84
84
|
By default it will use your first bank account, if you want to fetch transactions for a different account you can use this syntax:
|
85
85
|
|
86
|
-
$ bankscrap transactions YourBank your_iban --user YOUR_DNI --password YOUR_PASSWORD
|
86
|
+
$ bankscrap transactions YourBank --iban "your_iban" --user YOUR_DNI --password YOUR_PASSWORD
|
87
87
|
|
88
88
|
If you don't want to pass your user and password everytime you can define them in your .bash_profile by adding:
|
89
89
|
|
90
90
|
export BANK_SCRAP_USER=YOUR_BANK_USER
|
91
91
|
export BANK_SCRAP_PASSWORD=YOUR_BANK_PASSWORD
|
92
92
|
|
93
|
+
#### Export transactions to CSV
|
94
|
+
|
95
|
+
$ bankscrap transactions YourBank --user YOUR_BANK_USER --password YOUR_BANK_PASSWORD --format CSV [--output ./my_transactions.csv]
|
96
|
+
|
97
|
+
Currently only CSV is supported. The output parameter is optional, by default `transactions.csv` is used.
|
98
|
+
|
93
99
|
### From Ruby code
|
94
100
|
|
95
101
|
You can also use this gem from your own app as library. To do so first you must initialize a BankScrap::Bank object
|
96
102
|
|
97
103
|
|
98
104
|
```ruby
|
99
|
-
require 'bankscrap-bbva'
|
100
105
|
# BBVA
|
106
|
+
require 'bankscrap-bbva'
|
101
107
|
bbva = Bankscrap::BBVA::Bank.new(YOUR_BBVA_USER, YOUR_BBVA_PASSWORD)
|
108
|
+
|
102
109
|
# ING
|
110
|
+
require 'bankscrap-ing'
|
103
111
|
ing = Bankscrap::ING::Bank.new(YOUR_DNI, YOUR_ING_PASSWORD, extra_args: {"birthday" => "dd/mm/yyyy"})
|
104
112
|
```
|
105
113
|
|
data/lib/bankscrap/cli.rb
CHANGED
@@ -8,6 +8,10 @@ module Bankscrap
|
|
8
8
|
option :password, default: ENV['BANKSCRAP_PASSWORD']
|
9
9
|
option :log, default: false
|
10
10
|
option :debug, default: false
|
11
|
+
option :iban, default: nil
|
12
|
+
|
13
|
+
option :format
|
14
|
+
option :output
|
11
15
|
|
12
16
|
# Some bank needs more input, like birthday, this would go here
|
13
17
|
# Usage:
|
@@ -29,21 +33,18 @@ module Bankscrap
|
|
29
33
|
|
30
34
|
desc 'transactions BANK', "get account's transactions"
|
31
35
|
shared_options
|
32
|
-
|
36
|
+
options from: :string, to: :string
|
37
|
+
def transactions(bank)
|
33
38
|
assign_shared_options
|
34
39
|
|
35
|
-
|
36
|
-
|
37
|
-
end_date = @extra_args.key?('to') ? Date.strptime(@extra_args['to'], '%d-%m-%Y') : nil
|
38
|
-
rescue ArgumentError
|
39
|
-
say 'Invalid date format. Correct format d-m-Y', :red
|
40
|
-
end
|
40
|
+
start_date = parse_date(options[:from]) if options[:from]
|
41
|
+
end_date = parse_date(options[:to]) if options[:to]
|
41
42
|
|
42
43
|
initialize_client_for(bank)
|
43
44
|
|
44
|
-
account = iban ? @client.account_with_iban(iban) : @client.accounts.first
|
45
|
+
account = @iban ? @client.account_with_iban(@iban) : @client.accounts.first
|
45
46
|
|
46
|
-
if
|
47
|
+
if start_date && end_date
|
47
48
|
if start_date > end_date
|
48
49
|
say 'From date must be lower than to date', :red
|
49
50
|
exit
|
@@ -54,8 +55,9 @@ module Bankscrap
|
|
54
55
|
transactions = account.transactions
|
55
56
|
end
|
56
57
|
|
57
|
-
|
58
|
+
export_to_file(transactions, options[:format], options[:output]) if options[:format]
|
58
59
|
|
60
|
+
say "Transactions for: #{account.description} (#{account.iban})", :cyan
|
59
61
|
transactions.each do |transaction|
|
60
62
|
say transaction.to_s, (transaction.amount > Money.new(0) ? :green : :red)
|
61
63
|
end
|
@@ -66,6 +68,7 @@ module Bankscrap
|
|
66
68
|
def assign_shared_options
|
67
69
|
@user = options[:user]
|
68
70
|
@password = options[:password]
|
71
|
+
@iban = options[:iban]
|
69
72
|
@log = options[:log]
|
70
73
|
@debug = options[:debug]
|
71
74
|
@extra_args = options[:extra]
|
@@ -84,5 +87,25 @@ module Bankscrap
|
|
84
87
|
rescue NameError
|
85
88
|
raise ArgumentError.new("Invalid bank name. Did you mean \"#{bank_name.upcase}\"?")
|
86
89
|
end
|
90
|
+
|
91
|
+
def parse_date(string)
|
92
|
+
Date.strptime(string, '%d-%m-%Y')
|
93
|
+
rescue ArgumentError
|
94
|
+
say 'Invalid date format. Correct format d-m-Y (eg: 31-12-2016)', :red
|
95
|
+
exit
|
96
|
+
end
|
97
|
+
|
98
|
+
def export_to_file(data, format, path)
|
99
|
+
exporter(format, path).write_to_file(data)
|
100
|
+
end
|
101
|
+
|
102
|
+
def exporter(format, path)
|
103
|
+
case format.downcase
|
104
|
+
when 'csv' then BankScrap::Exporter::Csv.new(path)
|
105
|
+
else
|
106
|
+
say 'Sorry, file format not supported.', :red
|
107
|
+
exit
|
108
|
+
end
|
109
|
+
end
|
87
110
|
end
|
88
111
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module BankScrap
|
4
|
+
module Exporter
|
5
|
+
class Csv
|
6
|
+
HEADERS = %w(Date Description Amount).freeze
|
7
|
+
|
8
|
+
def initialize(output = nil)
|
9
|
+
@output = output || 'transactions.csv'
|
10
|
+
end
|
11
|
+
|
12
|
+
def write_to_file(data)
|
13
|
+
CSV.open(@output, 'wb') do |csv|
|
14
|
+
csv << HEADERS
|
15
|
+
data.each { |line| csv << line.to_a }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/bankscrap/version.rb
CHANGED
data/lib/bankscrap.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bankscrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Javier Cuevas
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- lib/bankscrap/bank.rb
|
147
147
|
- lib/bankscrap/cli.rb
|
148
148
|
- lib/bankscrap/config.rb
|
149
|
+
- lib/bankscrap/exporters/csv.rb
|
149
150
|
- lib/bankscrap/investment.rb
|
150
151
|
- lib/bankscrap/locale/en.yml
|
151
152
|
- lib/bankscrap/transaction.rb
|