portal_scraper 1.9.0 → 1.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/portal_scraper.rb +2 -3
- data/lib/portal_scraper/accounts/client.rb +14 -16
- data/lib/portal_scraper/parsing_helper.rb +19 -0
- data/lib/portal_scraper/version.rb +1 -1
- data/portal-scraper.gemspec +2 -0
- metadata +30 -3
- data/lib/portal_scraper/city_names_helper.rb +0 -8
- data/lib/portal_scraper/number_helper.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3fb1ca99f014e8e2b70a56e0a5e5d85946854c59362025407366eb3c2fcf2cf
|
4
|
+
data.tar.gz: 385ced44a825c3c23fe963a27d666685df4943a69c25dd92e7d99d8d4f50f297
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce42252c1c6fc81ae34df080a3859e30070a5ceb1afff3363149a501d41172bdcf570005e217218ca60675d32aae33c24aac23b53479e6be5c91bf691add02d2
|
7
|
+
data.tar.gz: b1aff4808f6fd405b5a9f1a5eff0571954d0c5462fbf183c399eb398bae9b2b2f7e974f80ba0da405044240c712ace23c6f890543869530f07046d0213dad334
|
data/lib/portal_scraper.rb
CHANGED
@@ -6,12 +6,11 @@ module PortalScraper
|
|
6
6
|
Config = Struct.new(:root_url, :app_id, :secret, :login_url, :token_url)
|
7
7
|
|
8
8
|
def self.configure
|
9
|
-
raise ArgumentError
|
9
|
+
raise ArgumentError, 'No block given' unless block_given?
|
10
|
+
|
10
11
|
yield config
|
11
12
|
end
|
12
13
|
|
13
|
-
private
|
14
|
-
|
15
14
|
def self.config
|
16
15
|
@config ||= Config.new
|
17
16
|
end
|
@@ -1,13 +1,11 @@
|
|
1
1
|
require 'mechanize'
|
2
2
|
require 'active_support/all'
|
3
|
-
require_relative '../
|
4
|
-
require_relative '../number_helper'
|
3
|
+
require_relative '../parsing_helper'
|
5
4
|
|
6
5
|
module PortalScraper
|
7
6
|
module Accounts
|
8
7
|
class Client
|
9
|
-
include
|
10
|
-
include NumberHelper
|
8
|
+
include ParsingHelper
|
11
9
|
attr_accessor :app_id, :secret
|
12
10
|
|
13
11
|
CODE_TO_COUNTRY_MAPPING = JSON.parse(File.read(File.join(File.dirname(__FILE__), 'code_to_country.json')))
|
@@ -16,10 +14,10 @@ module PortalScraper
|
|
16
14
|
def initialize(app_id = nil, secret = nil)
|
17
15
|
@app_id = app_id || config.app_id
|
18
16
|
@secret = secret || config.secret
|
19
|
-
raise BadRootUrl unless config.root_url =~ URI::
|
17
|
+
raise BadRootUrl unless config.root_url =~ URI::DEFAULT_PARSER.make_regexp
|
20
18
|
end
|
21
19
|
|
22
|
-
def
|
20
|
+
def scrap_accounts_balance
|
23
21
|
login
|
24
22
|
accounts_data = { accounts: [] }
|
25
23
|
|
@@ -32,19 +30,19 @@ module PortalScraper
|
|
32
30
|
result = transfer.click
|
33
31
|
result.search('table#operation tbody tr').each do |row|
|
34
32
|
transfers << {
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
operation_date: parse_date(row.search('td[1]')),
|
34
|
+
nature: row.search('td[2]').text.strip.gsub(/[\n,\t,'']/, ''),
|
35
|
+
value_date: parse_date(row.search('td[3]')),
|
36
|
+
debit: parse_number(row.search('td[4]')),
|
37
|
+
credit: parse_number(row.search('td[5]')),
|
40
38
|
}
|
41
39
|
end
|
42
40
|
end
|
43
41
|
accounts_data[:accounts] << {
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
client_ref: find_table_value(account, 'Identifiant tiers'),
|
43
|
+
balance: parse_number(account.search('table#contrat th.n')),
|
44
|
+
opened_on: parse_dates(account.search('table#contrat td'))&.max,
|
45
|
+
transfers: transfers,
|
48
46
|
}
|
49
47
|
end
|
50
48
|
|
@@ -65,7 +63,7 @@ module PortalScraper
|
|
65
63
|
form['commune'] = user[:codeInsee]
|
66
64
|
form['libCommune'] = user[:ville]
|
67
65
|
else
|
68
|
-
fill_commune(app, form, user[:codePostal],
|
66
|
+
fill_commune(app, form, user[:codePostal], parse_city_name(user[:ville]), user[:pays] || user[:libNation])
|
69
67
|
end
|
70
68
|
fill_address(form, user[:numeroVoie])
|
71
69
|
fill_birth_place(form, user[:paysNaissance])
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module PortalScraper
|
2
|
+
module ParsingHelper
|
3
|
+
def parse_city_name(node)
|
4
|
+
I18n.transliterate(node.upcase).gsub(/[^A-Z]/, ' ').sub(/\bSAINT\b/, 'ST')
|
5
|
+
end
|
6
|
+
|
7
|
+
def parse_number(node)
|
8
|
+
node.text.strip.gsub(/[[:space:]]+/, '').tr(',', '.').to_d
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse_date(node)
|
12
|
+
parse_dates(node).first
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse_dates(node)
|
16
|
+
node.text.strip.gsub(%r(\d{2}/\d{2}/\d{4}))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/portal-scraper.gemspec
CHANGED
@@ -30,4 +30,6 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency 'rake', '~> 10.0'
|
31
31
|
spec.add_development_dependency 'vcr'
|
32
32
|
spec.add_development_dependency 'webmock'
|
33
|
+
spec.add_development_dependency 'rubocop', '~> 0.67.2'
|
34
|
+
spec.add_development_dependency 'rubocop-performance'
|
33
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: portal_scraper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Armand Mégrot
|
@@ -109,6 +109,34 @@ dependencies:
|
|
109
109
|
- - ">="
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: rubocop
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 0.67.2
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 0.67.2
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rubocop-performance
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
112
140
|
description: Scrapping client for extranet portals.
|
113
141
|
email:
|
114
142
|
- armand.megrot@gmail.com
|
@@ -122,8 +150,7 @@ files:
|
|
122
150
|
- lib/portal_scraper/accounts/code_to_country.json
|
123
151
|
- lib/portal_scraper/bad_login_url.rb
|
124
152
|
- lib/portal_scraper/bad_root_url.rb
|
125
|
-
- lib/portal_scraper/
|
126
|
-
- lib/portal_scraper/number_helper.rb
|
153
|
+
- lib/portal_scraper/parsing_helper.rb
|
127
154
|
- lib/portal_scraper/portal_scraper_error.rb
|
128
155
|
- lib/portal_scraper/version.rb
|
129
156
|
- portal-scraper.gemspec
|