gares 2.0.0.pre.dev2 → 2.0.0.pre.dev3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Guardfile +1 -1
- data/lib/gares/train.rb +25 -3
- data/lib/gares/train_stop.rb +5 -5
- data/lib/gares/version.rb +1 -1
- data/spec/fixtures/get-train-6815 +6 -11
- data/spec/fixtures/get-train-6815-0 +0 -0
- data/spec/fixtures/get-train-6815-0-data +627 -0
- data/spec/fixtures/get-train-6815-1 +0 -0
- data/spec/fixtures/get-train-6815-1-data +367 -0
- data/spec/fixtures/post-train-6815 +0 -0
- data/spec/gares/search_spec.rb +6 -0
- data/spec/gares/train_spec.rb +20 -0
- data/spec/spec_helper.rb +13 -1
- data/tasks/fixtures.rake +17 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a13a56ca07337138e8c27caaeef89cd4ef6f4bf5
|
4
|
+
data.tar.gz: 0f0bd8cc2897185e17a06d0612df95dcb600db40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e552311ca4763dd804e95504c6e07876a51937e535afaf103424025ffee1b18d4a9f43b2c45aad32ffe2cc19a4bf1686642979097937d0b4b93cb56d49171b0
|
7
|
+
data.tar.gz: a91a6217481c551191637c6d38c0d8dd8b9304eaa8a57d1ab2422bbe0499e9deefa322f81269887802557ec5ff8f666218db0608a9f7e98afeb63b5ff1fe59ea
|
data/Guardfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
group 'gem' do
|
2
2
|
guard 'rspec', :cmd => "bundle exec rspec", :all_on_start => false, :all_after_pass => false, :failed_mode => :focus do
|
3
3
|
watch(%r{^spec/.+_spec\.rb$})
|
4
|
-
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/gares/#{m[1]}_spec.rb" }
|
4
|
+
watch(%r{^lib/gares/(.+)\.rb$}) { |m| "spec/gares/#{m[1]}_spec.rb" }
|
5
5
|
end
|
6
6
|
end
|
data/lib/gares/train.rb
CHANGED
@@ -42,19 +42,41 @@ module Gares
|
|
42
42
|
|
43
43
|
private
|
44
44
|
|
45
|
+
def itinerary_available?
|
46
|
+
document.css('ul.itinerary-details').size > 0
|
47
|
+
end
|
48
|
+
|
45
49
|
# Returns a new Nokogiri document for parsing.
|
46
50
|
def document
|
47
|
-
|
51
|
+
if !@document
|
52
|
+
@document = Nokogiri::HTML(self.class.request_sncf(@number, @date))
|
53
|
+
if !itinerary_available?
|
54
|
+
@document = Nokogiri::HTML(self.class.request_sncf_itinerary(0))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
@document
|
48
58
|
end
|
49
59
|
|
50
60
|
def self.request_sncf(number, date)
|
51
61
|
uri = URI.parse("http://www.sncf.com/sncf/train")
|
52
62
|
response = Net::HTTP.post_form(uri, {"numeroTrain" => number, "date" => date.strftime("%d/%m/%Y")})
|
53
|
-
cookies = response.get_fields('Set-Cookie').map { |cookie| cookie.split(";").first }.join(";")
|
63
|
+
@cookies = response.get_fields('Set-Cookie').map { |cookie| cookie.split(";").first }.join(";")
|
54
64
|
|
55
65
|
uri = URI.parse("http://www.sncf.com/en/horaires-info-trafic/train/resultats")
|
56
66
|
req = Net::HTTP::Get.new(uri.path)
|
57
|
-
req.add_field("Cookie", cookies)
|
67
|
+
req.add_field("Cookie", @cookies)
|
68
|
+
Net::HTTP.new(uri.host, uri.port).start { |http| http.request(req) }.body
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.request_sncf_itinerary(index)
|
72
|
+
uri = URI.parse("http://www.sncf.com/sncf/train/displayDetailTrain?idItineraire=#{index}")
|
73
|
+
req = Net::HTTP::Get.new(uri)
|
74
|
+
req.add_field("Cookie", @cookies) if @cookies
|
75
|
+
Net::HTTP.new(uri.host, uri.port).start { |http| http.request(req) }.body
|
76
|
+
|
77
|
+
uri = URI.parse("http://www.sncf.com/en/horaires-info-trafic/train/resultats?#{index}")
|
78
|
+
req = Net::HTTP::Get.new(uri)
|
79
|
+
req.add_field("Cookie", @cookies) if @cookies
|
58
80
|
Net::HTTP.new(uri.host, uri.port).start { |http| http.request(req) }.body
|
59
81
|
end
|
60
82
|
|
data/lib/gares/train_stop.rb
CHANGED
@@ -74,22 +74,22 @@ module Gares
|
|
74
74
|
raw_name = node.at('td.stations div.station').inner_html.strip
|
75
75
|
stations = Station.search(raw_name)
|
76
76
|
@station = if stations.size > 1
|
77
|
-
raw_name.gsub!(/[ -]/, '
|
77
|
+
raw_name.gsub!(/[ -]/, '.*')
|
78
78
|
exact_match = /^#{raw_name}$/i
|
79
79
|
begin_match = /^#{raw_name}/i
|
80
80
|
end_match = /#{raw_name}$/
|
81
81
|
middle_match = /#{raw_name}/i
|
82
82
|
stations.find do |station|
|
83
|
-
station.name.match(exact_match)
|
83
|
+
station.name.to_ascii.match(exact_match)
|
84
84
|
end ||
|
85
85
|
stations.find do |station|
|
86
|
-
station.name.match(begin_match)
|
86
|
+
station.name.to_ascii.match(begin_match)
|
87
87
|
end ||
|
88
88
|
stations.find do |station|
|
89
|
-
station.name.match(end_match)
|
89
|
+
station.name.to_ascii.match(end_match)
|
90
90
|
end ||
|
91
91
|
stations.find do |station|
|
92
|
-
station.name.match(middle_match)
|
92
|
+
station.name.to_ascii.match(middle_match)
|
93
93
|
end
|
94
94
|
else
|
95
95
|
stations.first
|
data/lib/gares/version.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
HTTP/1.1 200 OK
|
2
2
|
Content-Type: text/html;charset=UTF-8
|
3
3
|
X-UA-Compatible: IE=edge
|
4
|
-
Date:
|
5
|
-
Content-Length:
|
4
|
+
Date: Sun, 26 Apr 2015 20:19:36 GMT
|
5
|
+
Content-Length: 21606
|
6
6
|
Connection: keep-alive
|
7
7
|
Set-Cookie: SNC_city=SDN_PRD6; path=/; domain=.sncf.com
|
8
8
|
|
@@ -151,10 +151,10 @@ Modify your search </a>
|
|
151
151
|
<li class="itinerary-content ">
|
152
152
|
<input type="hidden" name="heure-depart" value="1429971360000" />
|
153
153
|
<input type="hidden" name="nb-correspondance" value="0" />
|
154
|
-
<input type="hidden" name="duree-trajet" value="
|
154
|
+
<input type="hidden" name="duree-trajet" value="381" />
|
155
155
|
<ul>
|
156
156
|
<li class="itinerary-abstract">
|
157
|
-
<div class="cell duration">Duration <strong>
|
157
|
+
<div class="cell duration">Duration <strong>6h21</strong></div>
|
158
158
|
<div class="cell connection">
|
159
159
|
Direct journey </div>
|
160
160
|
<div class="cell itinerary-message ">
|
@@ -190,11 +190,11 @@ Timetables </th>
|
|
190
190
|
<div class="train-number">no.<strong>6815</strong></div>
|
191
191
|
</td>
|
192
192
|
|
193
|
-
<td class="info
|
193
|
+
<td class="info center " rowspan="2">
|
194
194
|
<span class="titre">
|
195
195
|
On time
|
196
196
|
</span>
|
197
|
-
|
197
|
+
|
198
198
|
</td>
|
199
199
|
</tr>
|
200
200
|
<tr class="itinerary-end last ">
|
@@ -204,11 +204,6 @@ Timetables </th>
|
|
204
204
|
<td class="stations">
|
205
205
|
<div class="station">NICE VILLE</div>
|
206
206
|
</td>
|
207
|
-
<td class="info disruption">
|
208
|
-
<span class="titre">
|
209
|
-
Delayed arrival 5MIN
|
210
|
-
</span>
|
211
|
-
</td>
|
212
207
|
</tr>
|
213
208
|
</table>
|
214
209
|
<a href="/sncf/train/displayDetailTrain?idItineraire=0" class="plus" action="train/displayDetailTrain?idItineraire=0">+</a>
|
Binary file
|