bank_scrap 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -5
- data/lib/bank_scrap/bank.rb +0 -3
- data/lib/bank_scrap/banks/bankinter.rb +90 -25
- data/lib/bank_scrap/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 011bc3352dbc67fd3346b8214de8761910772cb7
|
4
|
+
data.tar.gz: 839d98e70e9755a1d8032e789f587655f7a52d55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ed3e531ad452268c55e95cfb3c8dd0eaa7bc4b9c46ad884f4f2a16a1e0bca5edeafb1d02337864dd85b2d240cfe893b9252f7bc0a92177b61eeedcb845a3dfe
|
7
|
+
data.tar.gz: 844bc92e681e981f6cede4963c1b64a0ffab36e3702fddf06fadd63c0c3e758fe61c85c4a671ee62afe4b140e1fdc756cebad0b1456820d057cc7ff6cb4e3973
|
data/README.md
CHANGED
@@ -10,8 +10,8 @@ Feel free to contribute and add your bank if it isn't supported.
|
|
10
10
|
|
11
11
|
| | BBVA | ING Direct | Bankinter |
|
12
12
|
|-----------------|:------:|:----------:|:---------:|
|
13
|
-
| Account Balance | ✓ | ✓ |
|
14
|
-
| Transactions | ✓ | ✓ |
|
13
|
+
| Account Balance | ✓ | ✓ | ✓ |
|
14
|
+
| Transactions | ✓ | ✓ | ✓ |
|
15
15
|
|
16
16
|
Interested in any other bank? Open a new Issue and we'll try to help.
|
17
17
|
|
@@ -54,12 +54,12 @@ Or, if you're using Bundler, just add the following to your Gemfile:
|
|
54
54
|
### From terminal
|
55
55
|
#### Bank account balance
|
56
56
|
|
57
|
-
###### BBVA
|
57
|
+
###### BBVA | Bankinter
|
58
58
|
|
59
|
-
$ bank_scrap balance
|
59
|
+
$ bank_scrap balance your_bank --user YOUR_BANK_USER --password YOUR_BANK_PASSWORD
|
60
60
|
|
61
61
|
###### ING Direct
|
62
|
-
ING needs one more argument: your
|
62
|
+
ING needs one more argument: your birthday.
|
63
63
|
|
64
64
|
$ bank_scrap balance ing --user YOUR_DNI --password YOUR_PASSWORD --extra=birthday:01/01/1980
|
65
65
|
|
@@ -96,6 +96,8 @@ require 'bank_scrap'
|
|
96
96
|
bbva = BankScrap::Bbva.new(YOUR_BBVA_USER, YOUR_BBVA_PASSWORD)
|
97
97
|
# ING
|
98
98
|
ing = BankScrap::Ing.new(YOUR_DNI, YOUR_ING_PASSWORD, extra_args: {"birthday" => "dd/mm/yyyy"})
|
99
|
+
# BANKINTER
|
100
|
+
bankinter = BankScrap::Bankinter.new(YOUR_BANKINTER_USER, YOUR_BANKINTER_PASSWORD)
|
99
101
|
```
|
100
102
|
|
101
103
|
|
data/lib/bank_scrap/bank.rb
CHANGED
@@ -3,9 +3,9 @@ require 'execjs'
|
|
3
3
|
|
4
4
|
module BankScrap
|
5
5
|
class Bankinter < Bank
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
BASE_ENDPOINT = "https://www.bankinter.com"
|
7
|
+
LOGIN_ENDPOINT = "/www/es-es/cgi/ebk+login"
|
8
|
+
TRANSACTIONS_ENDPOINT = "/www/es-es/cgi/ebk+opr+buscadormov"
|
9
9
|
|
10
10
|
def initialize(user, password, log: false, debug: false, extra_args: nil)
|
11
11
|
@user = user
|
@@ -14,50 +14,90 @@ module BankScrap
|
|
14
14
|
@debug = debug
|
15
15
|
|
16
16
|
initialize_connection
|
17
|
-
|
17
|
+
initialize_cookie(BASE_ENDPOINT)
|
18
|
+
parse_html(get(BASE_ENDPOINT + '/www/es-es/cgi/ebk+gc+lgin'))
|
18
19
|
login
|
20
|
+
super
|
19
21
|
end
|
20
22
|
|
21
|
-
def
|
23
|
+
def fetch_accounts
|
24
|
+
log 'fetch_accounts'
|
25
|
+
accounts = []
|
22
26
|
if @dashboard_doc
|
23
|
-
if links = @dashboard_doc.css('div.
|
24
|
-
links
|
27
|
+
if links = @dashboard_doc.css('div.caj_content_plegable.bk_ocultable_novisible div.tab_extracto_01')[0]
|
28
|
+
links.css('table tbody tr').each do |x|
|
29
|
+
name = x.css('td.enlace div form button').text.encode("UTF-8")
|
30
|
+
balance_currency = x.css('td.numero').text.scan(/[\d,\.]+|\D+/)
|
31
|
+
balance = balance_currency[0]
|
32
|
+
currency = balance_currency[1].gsub(/[[:space:]]/,"")
|
33
|
+
cc = x.css('td.enlace div form input')[0]['value']
|
34
|
+
data = {'id' => cc, 'description' => name, 'availableBalance' => balance, 'currency' => currency, 'iban' => cc}
|
35
|
+
|
36
|
+
accounts.push(build_account(data))
|
37
|
+
end
|
25
38
|
end
|
26
39
|
end
|
40
|
+
|
41
|
+
accounts
|
27
42
|
end
|
28
43
|
|
29
|
-
def
|
30
|
-
|
44
|
+
def fetch_transactions_for(account, start_date: Date.today - 1.month, end_date: Date.today)
|
45
|
+
transactions = []
|
46
|
+
|
47
|
+
fields = {
|
48
|
+
'ext-solapa' => 'operar',
|
49
|
+
'ext-subsolapa' => 'mis_cuentas',
|
50
|
+
'ordenDesc' => '',
|
51
|
+
'ordenFechaC' => 'A',
|
52
|
+
'ordenFechaV' => '',
|
53
|
+
'ordenGasto' => '',
|
54
|
+
'ordenIng' => '',
|
55
|
+
'buscador' => 'S',
|
56
|
+
'tipoConsulta' => 'N',
|
57
|
+
'seleccionado_tipo' => '',
|
58
|
+
'cuenta_seleccionada' => account.iban,
|
59
|
+
'tipoMov' => 'A',
|
60
|
+
'dia' => start_date.strftime("%d"),
|
61
|
+
'mes' => start_date.strftime("%m"),
|
62
|
+
'anio' => start_date.strftime("%Y"),
|
63
|
+
'diaH' => end_date.strftime("%d"),
|
64
|
+
'mesH' => end_date.strftime("%m"),
|
65
|
+
'anioH' => end_date.strftime("%Y"),
|
66
|
+
}
|
67
|
+
|
68
|
+
response = post(BASE_ENDPOINT + TRANSACTIONS_ENDPOINT, fields)
|
31
69
|
|
32
70
|
html_doc = Nokogiri::HTML(response)
|
33
71
|
|
34
|
-
html_transactions = html_doc.css('
|
72
|
+
html_transactions = html_doc.css('table#tablaDin_tabla tbody tr')
|
35
73
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
74
|
+
html_transactions.each do |x|
|
75
|
+
date = x.css('td.fecha')[0].text
|
76
|
+
description = x.css('td')[2].text
|
77
|
+
amount = x.css('td.numero').text.gsub(/\s+|\.|,/, "")
|
78
|
+
|
79
|
+
data = {'description' => description, 'amount' => amount, 'operationDate' => date, 'currency' => account.currency}
|
80
|
+
transactions.push(build_transaction(data, account));
|
41
81
|
end
|
42
82
|
|
83
|
+
transactions
|
43
84
|
end
|
44
85
|
|
45
86
|
private
|
46
87
|
|
47
88
|
def login
|
48
|
-
fields =
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
89
|
+
fields = {
|
90
|
+
'bkcache' => '',
|
91
|
+
'destino' => 'ebk+opr+extractointegral',
|
92
|
+
@id_field => 'username,password,psi',
|
93
|
+
@login_field => @login_param
|
94
|
+
}
|
54
95
|
|
55
96
|
response = post(BASE_ENDPOINT + LOGIN_ENDPOINT, fields)
|
56
97
|
|
57
|
-
|
58
|
-
|
59
|
-
@transactions_endpoint = @dashboard_doc.xpath('//div[@class="floatIzquierdo_md"]/form/@action')[0];
|
98
|
+
response = get(BASE_ENDPOINT + '/www/es-es/cgi/ebk+opr+extractointegral')
|
60
99
|
|
100
|
+
@dashboard_doc = Nokogiri::HTML(response, nil, "ISO-8859-1")
|
61
101
|
end
|
62
102
|
|
63
103
|
def parse_html(html)
|
@@ -67,7 +107,6 @@ module BankScrap
|
|
67
107
|
|
68
108
|
html_form = html_doc.css('form#fLogSecurity')
|
69
109
|
#TODO: Check if form is present if not retry initialize cookie for 5 attemps
|
70
|
-
|
71
110
|
@id_field = html_form.xpath('input[3]/@id')
|
72
111
|
|
73
112
|
js_source = 'var document = {};' + html_form.text
|
@@ -83,5 +122,31 @@ module BankScrap
|
|
83
122
|
|
84
123
|
@login_param = js_context.call(js_function, @user, @password, psi_actions)
|
85
124
|
end
|
125
|
+
|
126
|
+
def build_account(data)
|
127
|
+
Account.new(
|
128
|
+
bank: self,
|
129
|
+
id: data['id'],
|
130
|
+
balance: data['availableBalance'],
|
131
|
+
currency: data['currency'],
|
132
|
+
description: data['description'],
|
133
|
+
iban: data['iban']
|
134
|
+
)
|
135
|
+
end
|
136
|
+
|
137
|
+
def build_transaction(data, account)
|
138
|
+
amount = Money.new(data['amount'], data['currency'])
|
139
|
+
balance = data['accountBalanceAfterMovement'] ? Money.new(data['accountBalanceAfterMovement'] * 100, data['currency']) : nil
|
140
|
+
|
141
|
+
Transaction.new(
|
142
|
+
account: account,
|
143
|
+
id: data['id'],
|
144
|
+
amount: amount,
|
145
|
+
description: data['conceptDescription'] || data['description'],
|
146
|
+
effective_date: Date.strptime(data['operationDate'], "%d-%m-%Y"),
|
147
|
+
currency: data['currency'],
|
148
|
+
balance: balance
|
149
|
+
)
|
150
|
+
end
|
86
151
|
end
|
87
152
|
end
|
data/lib/bank_scrap/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bank_scrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ismael Sánchez
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-02-
|
14
|
+
date: 2015-02-08 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|