GareEnDirect 0.0.1
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 +7 -0
- data/.gitignore +22 -0
- data/.travis.yml +4 -0
- data/GareEnDirect.gemspec +26 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +1 -0
- data/lib/GareEnDirect/http_client.rb +26 -0
- data/lib/GareEnDirect/stations.rb +57 -0
- data/lib/GareEnDirect/version.rb +3 -0
- data/lib/GareEnDirect.rb +9 -0
- data/spec/lib/gares_spec.rb +54 -0
- data/spec/spec_helper.rb +8 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b02bf3ceffad3acd148b726a6beb14dacda918a8
|
4
|
+
data.tar.gz: f661bd55b2133fd223296a56c4cd3e3c0f576662
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 37df988a397ed3d6766b160c6d10e20f3c85a90fe0367c2676a6cde6636caa74dee754cba7d7d9ba87fc3245b7f29e6e5ca784af419f4abe430dcbb7a53487bd
|
7
|
+
data.tar.gz: c6f5c3802b05b3709d9861eebd0eb79dd29a7d359753285af358e95871c32eb9f28b2c81296a1a40a0784ae7057fc89dbf80b0e2172a925914580be2980d280b
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
.idea/
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
.bundle
|
5
|
+
.config
|
6
|
+
.yardoc
|
7
|
+
Gemfile.lock
|
8
|
+
InstalledFiles
|
9
|
+
coverage
|
10
|
+
InstalledFiles
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
|
19
|
+
# YARD artifacts
|
20
|
+
.yardoc
|
21
|
+
_yardoc
|
22
|
+
doc/
|
data/.travis.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'GareEnDirect/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'GareEnDirect'
|
8
|
+
spec.version = GareEnDirect::VERSION
|
9
|
+
spec.authors = ['Florian L.']
|
10
|
+
spec.email = ['florian@e-lam.net']
|
11
|
+
spec.description = %q{GareEnDirect - Toutes les informations de vos gares en direct (Scrapper de gares-en-mouvement.com)}
|
12
|
+
spec.summary = %q{GareEnDirect - Toutes les informations de vos gares en direct (Scrapper de gares-en-mouvement.com)}
|
13
|
+
spec.homepage = 'https://github.com/Florian95/GareEnDirect'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.1', '>= 10.1.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 2.14', '>= 2.14.1'
|
24
|
+
spec.add_development_dependency 'excon', '~> 0.26', '>= 0.26.0'
|
25
|
+
spec.add_development_dependency 'nokogiri', '~> 1.6', '>= 1.6.1'
|
26
|
+
end
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Florian LAMACHE
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Florian L.
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# GareEnDirect [](http://travis-ci.org/Florian95/GareEnDirect) [](https://codeclimate.com/github/Florian95/GareEnDirect) 
|
2
|
+
|
3
|
+
GareEnDirect - Toutes les informations de vos gares en direct (Scrapper de gares-en-mouvement.com)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'GareEnDirect'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install GareEnDirect
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Get all Stations
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
stations = GareEnDirect::Stations.new
|
25
|
+
```
|
26
|
+
|
27
|
+
### Get a specific station
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
station = GareEnDirect::Stations.new 'Lyon Part Dieu'
|
31
|
+
station.station_info
|
32
|
+
```
|
33
|
+
|
34
|
+
### Get next departures from a specific station
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
station = GareEnDirect::Stations.new 'Lyon Part Dieu'
|
38
|
+
station.next_departures
|
39
|
+
```
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module GareEnDirect
|
2
|
+
|
3
|
+
class HttpClient
|
4
|
+
|
5
|
+
URL = 'http://www.gares-en-mouvement.com/fr'
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(path)
|
12
|
+
begin
|
13
|
+
response = Excon.get(URL + path)
|
14
|
+
@doc = Nokogiri::HTML(response.body)
|
15
|
+
rescue => e
|
16
|
+
raise 'ERROR FETCHING OR PARSING'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def method_missing(m, *args, &block)
|
21
|
+
@doc.send(m, *args)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module GareEnDirect
|
2
|
+
|
3
|
+
class Stations
|
4
|
+
|
5
|
+
attr_accessor :stations, :station, :conn
|
6
|
+
|
7
|
+
def initialize(station_name = nil)
|
8
|
+
self.conn = GareEnDirect::HttpClient.new
|
9
|
+
all
|
10
|
+
if station_name
|
11
|
+
self.station = stations.select { |g| g[:name] == station_name }.first
|
12
|
+
raise "Station Doesn't Exists" if station.nil?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def all
|
17
|
+
self.conn.get('/')
|
18
|
+
self.stations = conn.search('#liste ul li').map do |elem|
|
19
|
+
{ref: elem.at('a').attributes['href'].value.gsub(/.+fr\/(\w+)\/accueil.+/, '\1'), name: elem.inner_text}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def station_info
|
24
|
+
self.conn.get('/' + self.station[:ref] + '/votre-gare/')
|
25
|
+
self.conn.search('.ouverture_heure li').map do |hours|
|
26
|
+
hours.inner_text
|
27
|
+
end.to_a
|
28
|
+
end
|
29
|
+
|
30
|
+
def next_departures
|
31
|
+
parse_horaires('dep')
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def next_arrivals
|
36
|
+
parse_horaires('arr')
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def parse_horaires(direction)
|
42
|
+
self.conn.get('/' + self.station[:ref] + '/horaires-temps-reel/' + direction + '/')
|
43
|
+
self.conn.search('table.tab_horaires_tps_reel tbody tr').map do |line|
|
44
|
+
{
|
45
|
+
transporteur: line.at('td.tvs_td_type').inner_text,
|
46
|
+
num_train: line.at('td.tvs_td_numero').inner_text,
|
47
|
+
time: line.at('td.tvs_td_heure').inner_text,
|
48
|
+
destination: line.at('td.tvs_td_originedestination').inner_text,
|
49
|
+
information: line.at('td.tvs_td_situation').inner_text,
|
50
|
+
voie: (line.at('td.tvs_td_voie').inner_text rescue '')
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
data/lib/GareEnDirect.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GareEnDirect::Stations do
|
4
|
+
|
5
|
+
it 'should list stations' do
|
6
|
+
obj = GareEnDirect::Stations.new
|
7
|
+
obj.stations.should be_an Array
|
8
|
+
obj.stations.should have(870).items
|
9
|
+
obj.stations[0].should eq({ref: 'frabt', name: 'Abancourt'})
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should raise error if station doesnt not exist : "Tombouctou"' do
|
13
|
+
expect { GareEnDirect::Stations.new('Tombouctou') }.to raise_error(RuntimeError, "Station Doesn't Exists")
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should select "Lyon Part Dieu"' do
|
17
|
+
obj = GareEnDirect::Stations.new 'Lyon Part Dieu'
|
18
|
+
obj.station.should_not be_an Array
|
19
|
+
obj.station.should be_a Hash
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should select "Lyon Part Dieu"' do
|
23
|
+
obj = GareEnDirect::Stations.new 'Lyon Part Dieu'
|
24
|
+
obj.station_info.should be_an Array
|
25
|
+
obj.station_info.should_not be_empty
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should have next departures' do
|
29
|
+
obj = GareEnDirect::Stations.new 'Lyon Part Dieu'
|
30
|
+
next_departures = obj.next_departures
|
31
|
+
next_departures.should be_an Array
|
32
|
+
next_departures.should have_at_least(20).items
|
33
|
+
next_departures[0].keys.should include(:num_train)
|
34
|
+
next_departures[0].keys.should include(:transporteur)
|
35
|
+
next_departures[0].keys.should include(:time)
|
36
|
+
next_departures[0].keys.should include(:destination)
|
37
|
+
next_departures[0].keys.should include(:information)
|
38
|
+
next_departures[0].keys.should include(:voie)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should have next arrivals' do
|
42
|
+
obj = GareEnDirect::Stations.new 'Lyon Part Dieu'
|
43
|
+
next_departures = obj.next_arrivals
|
44
|
+
next_departures.should be_an Array
|
45
|
+
next_departures.should have_at_least(20).items
|
46
|
+
next_departures[0].keys.should include(:num_train)
|
47
|
+
next_departures[0].keys.should include(:transporteur)
|
48
|
+
next_departures[0].keys.should include(:time)
|
49
|
+
next_departures[0].keys.should include(:destination)
|
50
|
+
next_departures[0].keys.should include(:information)
|
51
|
+
next_departures[0].keys.should include(:voie)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: GareEnDirect
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Florian L.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.1'
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 10.1.0
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '10.1'
|
44
|
+
- - '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 10.1.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.14'
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 2.14.1
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ~>
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '2.14'
|
64
|
+
- - '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 2.14.1
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: excon
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ~>
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0.26'
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 0.26.0
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ~>
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0.26'
|
84
|
+
- - '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 0.26.0
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
name: nokogiri
|
89
|
+
requirement: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.6'
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.6.1
|
97
|
+
type: :development
|
98
|
+
prerelease: false
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.6'
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 1.6.1
|
107
|
+
description: GareEnDirect - Toutes les informations de vos gares en direct (Scrapper
|
108
|
+
de gares-en-mouvement.com)
|
109
|
+
email:
|
110
|
+
- florian@e-lam.net
|
111
|
+
executables: []
|
112
|
+
extensions: []
|
113
|
+
extra_rdoc_files: []
|
114
|
+
files:
|
115
|
+
- .gitignore
|
116
|
+
- .travis.yml
|
117
|
+
- GareEnDirect.gemspec
|
118
|
+
- Gemfile
|
119
|
+
- LICENSE
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- lib/GareEnDirect.rb
|
124
|
+
- lib/GareEnDirect/http_client.rb
|
125
|
+
- lib/GareEnDirect/stations.rb
|
126
|
+
- lib/GareEnDirect/version.rb
|
127
|
+
- spec/lib/gares_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
homepage: https://github.com/Florian95/GareEnDirect
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - '>='
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.2.2
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: GareEnDirect - Toutes les informations de vos gares en direct (Scrapper de
|
153
|
+
gares-en-mouvement.com)
|
154
|
+
test_files:
|
155
|
+
- spec/lib/gares_spec.rb
|
156
|
+
- spec/spec_helper.rb
|