portal_scraper 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31516d14a7a801b838c845184d8c561170532c39cedb017efe9c543fdf5ecc9c
4
- data.tar.gz: 7858244b3bfca539c9303f8bad9e0cfaaa0bfe1116ca34f67782ee97f112ffad
3
+ metadata.gz: 3f511d4ae5d6568df6bc6960907a0964ecfb6c8f0c8d5850b5ad757a0ed35039
4
+ data.tar.gz: 5edb4fdbd33676d7b03623a86815b0b865fd214d85e4cd6e34e7fe42fa67204b
5
5
  SHA512:
6
- metadata.gz: 8ca16dace317cacf3f1351d7009c29ef1231341372f764c34182f866727ca2e155fca3f90487d9d3a36ef4e296a12db5be12deef452288f5d4d18c2558059c86
7
- data.tar.gz: fe54374b24f9252cc4186208b5947d5de58ddf77c9541a868774eedae939a3e02218466f23b08398722948e6b85c0c917661fd3a68c7e7e1b2e2dc698902cc80
6
+ metadata.gz: 5df684726b58e1d8da72af7abd8b0395d36bc403f8d045ef0abbf628a8eee0aeebaa13f13ecbc9e80b9ff1dd088695eec92470dac707d5e5977dab1961196234
7
+ data.tar.gz: d93c42d08e8f39ddacf8828060e91324f0ad1b42f1f131b381d43ba693bbba8d05c3d82e1c669736fc153d087b9f648ba1af8fab7936be25c70ee10d811c2708
@@ -21,35 +21,35 @@ module PortalScraper
21
21
  login
22
22
  accounts_data = { accounts: [] }
23
23
 
24
- results = app.post(url_for('/appRecherche.do'), { nom: '', prenom: '', chercher: 'Chercher' })
24
+ user_page = app.post(url_for('/appRecherche.do'), { nom: '', prenom: '', chercher: 'Chercher' })
25
25
  loop do
26
- results.links_with(href: /appTiersDetail.do/).each do |link|
27
- account = link.click
28
- transfers = []
29
- account.links_with(css: 'table#contrat td a').each do |transfer|
30
- result = transfer.click
31
- result.search('table#operation tbody tr').each do |row|
32
- transfers << {
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]')),
38
- }
26
+ user_page.links_with(href: /appTiersDetail.do/).each do |link|
27
+ account = link.click
28
+ selected_row = nil
29
+ selected_row_date = nil
30
+
31
+ account.links_with(css: 'table#contrat td a').each do |row|
32
+ row_date = parse_date(row.node.ancestors('tr').at('td[2]'))&.to_date
33
+ if selected_row_date.nil? || selected_row_date < row_date
34
+ selected_row_date = row_date
35
+ selected_row = row
39
36
  end
40
37
  end
38
+
39
+ transfers = scrap_transfers(selected_row)
40
+ balance = selected_row&.node&.ancestors('tr')&.at('td[4]')
41
41
  accounts_data[:accounts] << {
42
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,
43
+ balance: balance.nil? ? "0".to_d : parse_number(balance),
44
+ opened_on: selected_row_date.nil? ? parse_dates(account.search('table#contrat td'))&.max : selected_row_date.to_s,
45
45
  transfers: transfers,
46
46
  }
47
47
  end
48
48
 
49
- break unless results.search('.pg_next').present?
49
+ break unless user_page.search('.pg_next').present?
50
50
  # Need to fetch the first page as you cannot navigate from client back to research page
51
51
  app.post(url_for('/appRecherche.do'), { nom: '', prenom: '', chercher: 'Chercher' })
52
- results = app.get(results.search('a.pg_next').first['href'])
52
+ user_page = app.get(user_page.search('a.pg_next').first['href'])
53
53
  end
54
54
  accounts_data
55
55
  end
@@ -174,6 +174,23 @@ module PortalScraper
174
174
  def config
175
175
  PortalScraper.config
176
176
  end
177
+
178
+ def scrap_transfers(selected_row)
179
+ transfers = []
180
+ transfers_page = selected_row&.click
181
+ if transfers_page
182
+ transfers_page.search('table#operation tbody tr').each do |row|
183
+ transfers << {
184
+ operation_date: parse_date(row.search('td[1]')),
185
+ nature: row.search('td[2]').text.strip.gsub(/[\n,\t,'']/, ''),
186
+ value_date: parse_date(row.search('td[3]')),
187
+ debit: parse_number(row.search('td[4]')),
188
+ credit: parse_number(row.search('td[5]')),
189
+ }
190
+ end
191
+ end
192
+ transfers
193
+ end
177
194
  end
178
195
  end
179
196
  end
@@ -2,7 +2,7 @@ module PortalScraper
2
2
  class Version
3
3
  MAJOR = 2
4
4
  MINOR = 0
5
- PATCH = 0
5
+ PATCH = 1
6
6
 
7
7
  def self.to_s
8
8
  [MAJOR, MINOR, PATCH].compact.join('.')
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.0
4
+ version: 2.0.1
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-05 00:00:00.000000000 Z
12
+ date: 2020-01-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mechanize