portal_scraper 2.0.3 → 2.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56fa7cb02271ba8d4399e8e9dc1e8bc966b8740e88657f604367a33ab0ff42df
4
- data.tar.gz: '0582f340a21e6ed99268c8e6a06dcc344ea711dd7260f4d467b35ddfd4bb62e4'
3
+ metadata.gz: '009002ad1b898fbfd1b7aa934da6e15acf6c74b0a065d9c7c95060433ff3eff8'
4
+ data.tar.gz: 7775cc6cb2ed570c50b25783e399a0008be103196f7b70f749b4affb35773012
5
5
  SHA512:
6
- metadata.gz: 209a4b05439f3c5d804f2bb3f742a0f0ec1e6f30735d29a60444f2901bdd29c79e42c64ac62f5081d2478326d7bde7537ea2b8edd292ea6772d07b44e5cd8ed1
7
- data.tar.gz: e31eaa22c79c62f3f8e39342771a8251bb3d5594cccf5b413f08e3f23533c70bf50983434d691a21ff877698c33ae188e543f172b40fed10dd8853e078caf595
6
+ metadata.gz: 1040fc3657d32bb490a38b7896016b009c53c69da99988568adf9aafb01fcc82b8c406cd18d4ac5dab6d3904ebffd08792cf82bf50b19b5a810e254517e3e3c6
7
+ data.tar.gz: 62fe9b8a3110ea2944849dfa58927556e43511b81d2ed1529fa93235cd95ef636cfb86848d6c813567a60ab8266bd53a73fd6051e91b11c67958022b78d9c808
@@ -9,6 +9,7 @@ module PortalScraper
9
9
  attr_accessor :app_id, :secret
10
10
 
11
11
  CODE_TO_COUNTRY_MAPPING = JSON.parse(File.read(File.join(File.dirname(__FILE__), 'code_to_country.json')))
12
+ IS_POSTAL_CODE_DOM = JSON.parse(File.read(File.join(File.dirname(__FILE__), 'is_postal_code_dom.json')))
12
13
  MINIMUM_AMOUNT = 10
13
14
 
14
15
  def initialize(app_id = nil, secret = nil)
@@ -24,8 +25,8 @@ module PortalScraper
24
25
  user_page = app.post(url_for('/appRecherche.do'), { nom: '', prenom: '', chercher: 'Chercher' })
25
26
  loop do
26
27
  user_page.links_with(href: /appTiersDetail.do/).each do |link|
27
- account = link.click
28
- selected_link = nil
28
+ account = link.click
29
+ selected_link = nil
29
30
  opened_on, balance = nil, 0.to_d
30
31
 
31
32
  account.links_with(css: 'table#contrat td a').each do |account_link|
@@ -36,8 +37,8 @@ module PortalScraper
36
37
  next unless opened_on.nil? || opened_on < row_date
37
38
 
38
39
  selected_link = account_link
39
- opened_on = row_date
40
- balance = parse_number(row.at('td[5]'))
40
+ opened_on = row_date
41
+ balance = parse_number(row.at('td[5]'))
41
42
  end
42
43
 
43
44
  next unless selected_link
@@ -68,7 +69,7 @@ module PortalScraper
68
69
  form['commune'] = user[:codeInsee]
69
70
  form['libCommune'] = user[:ville]
70
71
  else
71
- fill_commune(app, form, user[:codePostal], parse_city_name(user[:ville]), user[:pays] || user[:libNation])
72
+ fill_commune(app, form, user[:codePostal], parse_city_name(user[:ville]))
72
73
  end
73
74
  fill_address(form, user[:numeroVoie])
74
75
  fill_birth_place(form, user[:paysNaissance])
@@ -85,6 +86,8 @@ module PortalScraper
85
86
  end
86
87
  end
87
88
  nil
89
+ rescue => e
90
+ { error: e.message }
88
91
  end
89
92
 
90
93
  def create_proposition(client_ref)
@@ -148,14 +151,15 @@ module PortalScraper
148
151
  end
149
152
  end
150
153
 
151
- def fill_commune(app, form, postal_code, city, country_code)
154
+ def fill_commune(app, form, postal_code, city)
152
155
  app.post(url_for('/tiersCommunes.do'), { codPos: postal_code }).tap do |mappings|
153
- cities = mappings.search('td.t').map { |c| { code: c.parent.search('a.PL_LST').text.strip, name: c.text.strip } }
154
- matched_city = cities.find(-> { cities.first }) { |c| c[:name].include?(city) }
156
+ cities = mappings.search('td.t').map { |c| { code: c.parent.search('a.PL_LST').text.strip, name: c.text.strip } }
157
+ matched_city = cities.find(-> { cities.first }) { |c| c[:name].include?(city) }
158
+ raise "City '#{city}' and postcode '#{postal_code}' not found" unless matched_city
155
159
  form['commune'] = matched_city[:code]
156
160
  form['libCommune'] = matched_city[:name]
157
161
  end
158
- form['territoireRes'] = CODE_TO_COUNTRY_MAPPING.dig(country_code, 'category')
162
+ form['territoireRes'] = IS_POSTAL_CODE_DOM.dig(postal_code[0..2], 'category') || 0
159
163
  end
160
164
 
161
165
  def fill_address(form, address)
@@ -0,0 +1 @@
1
+ {"971":{"name":"GUADELOUPE","category":1},"972":{"name":"MARTINIQUE","category":1},"973":{"name":"GUYANE FRANCAISE","category":1},"974":{"name":"REUNION","category":1}}
@@ -1,7 +1,7 @@
1
1
  module PortalScraper
2
2
  class Version
3
3
  MAJOR = 2
4
- MINOR = 0
4
+ MINOR = 1
5
5
  PATCH = 3
6
6
 
7
7
  def self.to_s
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: 2.0.3
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Armand Mégrot
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-01-08 00:00:00.000000000 Z
12
+ date: 2020-02-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mechanize
@@ -148,6 +148,7 @@ files:
148
148
  - lib/portal_scraper.rb
149
149
  - lib/portal_scraper/accounts/client.rb
150
150
  - lib/portal_scraper/accounts/code_to_country.json
151
+ - lib/portal_scraper/accounts/is_postal_code_dom.json
151
152
  - lib/portal_scraper/bad_login_url.rb
152
153
  - lib/portal_scraper/bad_root_url.rb
153
154
  - lib/portal_scraper/parsing_helper.rb