colissimo_zone 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +63 -5
- data/lib/colissimo_zone/version.rb +1 -1
- data/lib/data/colissimo_zones.yaml +68 -0
- metadata +1 -1
data/Rakefile
CHANGED
@@ -10,14 +10,72 @@ task :update do
|
|
10
10
|
require 'yaml'
|
11
11
|
require 'bigdecimal'
|
12
12
|
|
13
|
+
data = []
|
14
|
+
|
15
|
+
zone_prices = {
|
16
|
+
BigDecimal("12.70") => "1",
|
17
|
+
BigDecimal("15.20") => "2",
|
18
|
+
}
|
19
|
+
|
20
|
+
browser = Watir::Browser.new
|
21
|
+
browser.goto 'http://www.colissimo.fr/'
|
22
|
+
browser.link(:text => "Envoyer un colis").click
|
23
|
+
browser.link(:text => "Colissimo Outre-mer").click
|
24
|
+
browser.link(:text => "Calculer le tarif").click
|
25
|
+
|
26
|
+
country_select = browser.select_list(:name => 'paysDestinationFicheProduit')
|
27
|
+
Watir::Wait.until { country_select.options.size > 0 }
|
28
|
+
doc = Nokogiri::HTML(country_select.html)
|
29
|
+
options = doc.css("option")
|
30
|
+
options.shift
|
31
|
+
countries = options.map { |option| [option["value"], option.text] }
|
32
|
+
|
33
|
+
countries.each do |code, name|
|
34
|
+
country_select.select name
|
35
|
+
|
36
|
+
solution_select = browser.select_list(:name => 'solutionAffranchissement')
|
37
|
+
solution_select.when_present.select "Guichet"
|
38
|
+
browser.text_field(:name => 'poids').when_present.set '1'
|
39
|
+
Watir::Wait.until { browser.select_list(:name => 'natureEnvoi').options.size > 0 }
|
40
|
+
if browser.select_list(:name => 'natureEnvoi').option(:text => "Standard").present?
|
41
|
+
select_option = "Standard"
|
42
|
+
price_diff = 0
|
43
|
+
standard_available = true
|
44
|
+
else
|
45
|
+
select_option = "Non standard"
|
46
|
+
price_diff = 6
|
47
|
+
standard_available = false
|
48
|
+
end
|
49
|
+
browser.select_list(:name => 'natureEnvoi').select select_option
|
50
|
+
browser.image(:src => "img/misc/boutonCalculTarif.gif").when_present.click
|
51
|
+
price_text = browser.p(:class => "price").when_present.text
|
52
|
+
price, = price_text.scan(/(\d+\.\d{2})/).first
|
53
|
+
if price
|
54
|
+
price = BigDecimal(price) - price_diff
|
55
|
+
zone = zone_prices[price]
|
56
|
+
puts "Zone not found for price #{price.to_s} on #{name}" unless zone
|
57
|
+
else
|
58
|
+
puts "No price on #{name}"
|
59
|
+
zone = nil
|
60
|
+
end
|
61
|
+
country_data = {
|
62
|
+
name: name,
|
63
|
+
code: code,
|
64
|
+
zone: zone,
|
65
|
+
standard_available: standard_available,
|
66
|
+
}
|
67
|
+
p country_data
|
68
|
+
data << country_data
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
|
13
73
|
zone_prices = {
|
14
74
|
BigDecimal("16.15") => "A",
|
15
75
|
BigDecimal("19.80") => "B",
|
16
76
|
BigDecimal("23.20") => "C",
|
17
77
|
BigDecimal("26.40") => "D",
|
18
78
|
}
|
19
|
-
|
20
|
-
browser = Watir::Browser.new
|
21
79
|
browser.goto 'http://www.colissimo.fr/'
|
22
80
|
browser.link(:text => "Envoyer un colis").click
|
23
81
|
browser.link(:text => "Colissimo International").click
|
@@ -31,8 +89,6 @@ task :update do
|
|
31
89
|
options.shift
|
32
90
|
countries = options.map { |option| [option["value"], option.text] }
|
33
91
|
|
34
|
-
data = []
|
35
|
-
|
36
92
|
countries.each do |code, name|
|
37
93
|
country_select.select name
|
38
94
|
browser.text_field(:name => 'poids').when_present.set '1'
|
@@ -68,8 +124,10 @@ task :update do
|
|
68
124
|
p country_data
|
69
125
|
data << country_data
|
70
126
|
end
|
71
|
-
|
127
|
+
|
72
128
|
File.open("lib/data/colissimo_zones.yaml", "w") do |f|
|
73
129
|
f.write data.to_yaml
|
74
130
|
end
|
131
|
+
|
132
|
+
browser.close
|
75
133
|
end
|
@@ -1,4 +1,72 @@
|
|
1
1
|
---
|
2
|
+
- :name: GUADELOUPE
|
3
|
+
:code: GP
|
4
|
+
:zone: '1'
|
5
|
+
:standard_available: true
|
6
|
+
- :name: GUYANE FRANÇAISE
|
7
|
+
:code: GF
|
8
|
+
:zone: '1'
|
9
|
+
:standard_available: true
|
10
|
+
- :name: MARTINIQUE
|
11
|
+
:code: MQ
|
12
|
+
:zone: '1'
|
13
|
+
:standard_available: true
|
14
|
+
- :name: MAYOTTE
|
15
|
+
:code: YT
|
16
|
+
:zone: '1'
|
17
|
+
:standard_available: true
|
18
|
+
- :name: NAVIRES DE L'ARMEE
|
19
|
+
:code: NAV
|
20
|
+
:zone:
|
21
|
+
:standard_available: true
|
22
|
+
- :name: NOUVELLE-CALÉDONIE
|
23
|
+
:code: NC
|
24
|
+
:zone: '2'
|
25
|
+
:standard_available: true
|
26
|
+
- :name: POLYNÉSIE FRANÇAISE
|
27
|
+
:code: PF
|
28
|
+
:zone: '2'
|
29
|
+
:standard_available: true
|
30
|
+
- :name: RÉUNION
|
31
|
+
:code: RE
|
32
|
+
:zone: '1'
|
33
|
+
:standard_available: true
|
34
|
+
- :name: SAINT-BARTHÉLEMY
|
35
|
+
:code: GP2
|
36
|
+
:zone: '1'
|
37
|
+
:standard_available: true
|
38
|
+
- :name: SAINT-MARTIN
|
39
|
+
:code: GP3
|
40
|
+
:zone: '1'
|
41
|
+
:standard_available: true
|
42
|
+
- :name: SAINT-PIERRE-ET-MIQUELON
|
43
|
+
:code: PM
|
44
|
+
:zone: '1'
|
45
|
+
:standard_available: true
|
46
|
+
- :name: WALLIS ET FUTUNA
|
47
|
+
:code: WF
|
48
|
+
:zone: '2'
|
49
|
+
:standard_available: true
|
50
|
+
- :name: 25000 (SECTEUR POSTAL)
|
51
|
+
:code: FS2
|
52
|
+
:zone:
|
53
|
+
:standard_available: true
|
54
|
+
- :name: 55000 (SECTEUR POSTAL)
|
55
|
+
:code: FS5
|
56
|
+
:zone:
|
57
|
+
:standard_available: true
|
58
|
+
- :name: 69000 (SECTEUR POSTAL)
|
59
|
+
:code: FS6
|
60
|
+
:zone:
|
61
|
+
:standard_available: true
|
62
|
+
- :name: 71000 (SECTEUR POSTAL)
|
63
|
+
:code: FS7
|
64
|
+
:zone:
|
65
|
+
:standard_available: true
|
66
|
+
- :name: 85000 (SECTEUR POSTAL)
|
67
|
+
:code: FS8
|
68
|
+
:zone:
|
69
|
+
:standard_available: true
|
2
70
|
- :name: Afghanistan
|
3
71
|
:code: AF
|
4
72
|
:zone: D
|