diMLOrb 0.0.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/Gemfile.lock +30 -0
- data/README.rdoc +18 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/diMLOrb.gemspec +75 -0
- data/lib/diMLOrb.rb +23 -6
- data/lib/stations.rb +34 -0
- metadata +9 -5
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.8.7@diMLOrb
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.5.2)
|
7
|
+
bundler (~> 1.0.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
nokogiri (1.5.0)
|
11
|
+
rake (0.9.2)
|
12
|
+
rcov (0.9.9)
|
13
|
+
rspec (2.3.0)
|
14
|
+
rspec-core (~> 2.3.0)
|
15
|
+
rspec-expectations (~> 2.3.0)
|
16
|
+
rspec-mocks (~> 2.3.0)
|
17
|
+
rspec-core (2.3.1)
|
18
|
+
rspec-expectations (2.3.0)
|
19
|
+
diff-lcs (~> 1.1.2)
|
20
|
+
rspec-mocks (2.3.0)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
bundler (~> 1.0.0)
|
27
|
+
jeweler (~> 1.5.2)
|
28
|
+
nokogiri
|
29
|
+
rcov
|
30
|
+
rspec (~> 2.3.0)
|
data/README.rdoc
CHANGED
@@ -1,6 +1,23 @@
|
|
1
1
|
= diMLOrb
|
2
2
|
|
3
|
-
|
3
|
+
*diMLOrb* is a gem that helps you programmatically grab the timetables of the Metro Ligero Oeste (MLO) in the Madrid Community.
|
4
|
+
|
5
|
+
*diMLOrb* is mainly web scraping the MLO official website (diMLO): http://www.dimlo.es/Informate/calc.aspx
|
6
|
+
|
7
|
+
I just did this little tool in order to have a single click app in my iphone to check the timetable of the train I have to get everyday. For that purpose I created http://dimloya.heroku.com/ which uses this gem.
|
8
|
+
|
9
|
+
Currently my little website _diMLOya_ supports only 2 stations of all the network. If someone is ever interested in having support for the whole nextwork I would be more than happy to finish the job, until then I'll leave it like that (I'm a lazy guy :P)
|
10
|
+
|
11
|
+
Note that this gems depends on the diMLO website which oftenly tends to be down or not responsive.
|
12
|
+
|
13
|
+
|
14
|
+
= Example of Usage
|
15
|
+
require 'diMLOrb'
|
16
|
+
#say I want to go from Pozuelo Oeste station to Colonia Jardín station
|
17
|
+
d = DiMLOrb::DiMLOrb.new(:PozueloOeste, :ColoniaJardin)
|
18
|
+
d.proximo # => (in minutes) amount of time first train will take to get to Pozuelo Oeste
|
19
|
+
d.siguiente # => (in minutes) amount of time second train will take to get to Pozuelo Oeste
|
20
|
+
d.duracion # => (in minutes) amount of time it will take the train to get from Pozuelo Oeste to Colonia Jardin
|
4
21
|
|
5
22
|
== Contributing to diMLOrb
|
6
23
|
|
data/Rakefile
CHANGED
@@ -16,7 +16,7 @@ Jeweler::Tasks.new do |gem|
|
|
16
16
|
gem.homepage = "http://github.com/ariera/diMLOrb"
|
17
17
|
gem.license = "MIT"
|
18
18
|
gem.summary = %Q{Ruby API for the diMLO web timetable service}
|
19
|
-
gem.description = %Q{This gem acts as an API to the MLO (Metro Ligero Oeste) public transportation of Madrid, allowing the user get
|
19
|
+
gem.description = %Q{This gem acts as an API to the MLO (Metro Ligero Oeste) public transportation of Madrid, allowing the user get ETAs of the next 2 trains}
|
20
20
|
gem.email = "ariera@gmail.com"
|
21
21
|
gem.authors = ["ariera"]
|
22
22
|
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.1.1
|
data/diMLOrb.gemspec
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{diMLOrb}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["ariera"]
|
12
|
+
s.date = %q{2011-07-17}
|
13
|
+
s.description = %q{This gem acts as an API to the MLO (Metro Ligero Oeste) public transportation of Madrid, allowing the user get ETAs of the next 2 trains}
|
14
|
+
s.email = %q{ariera@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
".rvmrc",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"diMLOrb.gemspec",
|
30
|
+
"lib/diMLOrb.rb",
|
31
|
+
"lib/stations.rb",
|
32
|
+
"spec/diMLOrb_spec.rb",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/ariera/diMLOrb}
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.6.2}
|
39
|
+
s.summary = %q{Ruby API for the diMLO web timetable service}
|
40
|
+
s.test_files = [
|
41
|
+
"spec/diMLOrb_spec.rb",
|
42
|
+
"spec/spec_helper.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
51
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
53
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
54
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
58
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
59
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
60
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
61
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
62
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
63
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
64
|
+
end
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
67
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
68
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
69
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
70
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
71
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
72
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
data/lib/diMLOrb.rb
CHANGED
@@ -2,19 +2,28 @@
|
|
2
2
|
require 'net/http'
|
3
3
|
require 'uri'
|
4
4
|
require 'nokogiri'
|
5
|
+
require 'stations'
|
5
6
|
|
6
7
|
module DiMLOrb
|
7
8
|
class DiMLOrb
|
8
|
-
STATIONS = {:colonia_jardin => "Colonia Jardín|ECJ|ML2", :somosaguas_sur => "Somosaguas Sur|SSU|ML2"}
|
9
|
+
#STATIONS = {:colonia_jardin => "Colonia Jardín|ECJ|ML2", :somosaguas_sur => "Somosaguas Sur|SSU|ML2"}
|
9
10
|
attr_accessor :uri, :http, :html, :viewstate, :eventvalidation, :proximo, :siguiente, :cookie, :data, :duracion, :from, :to
|
10
|
-
|
11
|
-
|
11
|
+
|
12
|
+
# DiMLOrb.new receives the Metro Ligero Oeste station you are going from and your desired destination
|
13
|
+
# it returns you an object with mainly 3 attributes:
|
14
|
+
# => proximo = next train arrives in X minutes
|
15
|
+
# => siguiente = the following train arrives in Y minutes
|
16
|
+
# => duraction = how long should it take to go from one station to the other
|
17
|
+
def initialize(from = :ColoniaJardin, to = :SomosaguasSur)
|
18
|
+
@from, @to = STATIONS[from], STATIONS[to]
|
12
19
|
@uri = URI.parse("http://www.dimlo.es/Informate/calc.aspx")
|
13
20
|
@http = Net::HTTP.new(@uri.host, @uri.port)
|
14
21
|
get_validations
|
15
22
|
get_times
|
16
23
|
end
|
17
|
-
|
24
|
+
|
25
|
+
# diMLO website uses cookies and token validations (aka protect from forgery) in its forms
|
26
|
+
# *get_validations* grabs this values, namely: cookie, viewstate and eventvalidation
|
18
27
|
def get_validations
|
19
28
|
resp = @http.get(@uri.path)
|
20
29
|
raise "HTTP Error: #{resp.code}" if resp.code.to_i != 200
|
@@ -25,6 +34,8 @@ module DiMLOrb
|
|
25
34
|
@eventvalidation = doc.css('#__EVENTVALIDATION').attr('value').value
|
26
35
|
end
|
27
36
|
|
37
|
+
# *get_times* asks diMLO website for the next metro timetable and parses the html
|
38
|
+
# to grab the values of _proximo_, _siguiente_ and _duracion_
|
28
39
|
def get_times
|
29
40
|
#@html = Net::HTTP.post_form(@uri, options)
|
30
41
|
req = Net::HTTP::Post.new(@uri.request_uri)
|
@@ -37,6 +48,9 @@ module DiMLOrb
|
|
37
48
|
@duracion = doc.css('#DuracionTXT').inner_text
|
38
49
|
end
|
39
50
|
|
51
|
+
protected
|
52
|
+
|
53
|
+
# options needed in the form to get the timetables
|
40
54
|
def options
|
41
55
|
{
|
42
56
|
'origenDDL' => @from,
|
@@ -47,6 +61,8 @@ module DiMLOrb
|
|
47
61
|
'btnCalcular.y' =>'5'
|
48
62
|
}
|
49
63
|
end
|
64
|
+
|
65
|
+
# headers with the validation tokens, etc, needed to ask for the timetables
|
50
66
|
def headers
|
51
67
|
{
|
52
68
|
'Cookie' => @cookie,
|
@@ -61,16 +77,17 @@ module DiMLOrb
|
|
61
77
|
'Referer' => 'http://www.dimlo.es/Informate/calc.aspx'}
|
62
78
|
end
|
63
79
|
|
80
|
+
# debugging function
|
64
81
|
def to_file(file_name = 'dimlo.html')
|
65
82
|
f = File.new(file_name, "w+")
|
66
83
|
f.puts @html
|
67
84
|
`open #{file_name}`
|
68
85
|
end
|
69
|
-
|
86
|
+
# debugging function
|
70
87
|
def from
|
71
88
|
@from.split("|").first
|
72
89
|
end
|
73
|
-
|
90
|
+
# debugging function
|
74
91
|
def to
|
75
92
|
@to.split("|").first
|
76
93
|
end
|
data/lib/stations.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module DiMLOrb
|
2
|
+
|
3
|
+
STATIONS = {
|
4
|
+
:ColoniaJardin=>"Colonia Jardín|ECJ|ML2",
|
5
|
+
:PradoDeLaVega=>"Prado de la Vega|PVE|ML2",
|
6
|
+
:ColoniaDeLosAngeles=>"Colonia de Los Ángeles|CLA|ML2",
|
7
|
+
:PradoDelRey=>"Prado del Rey|PRE|ML2",
|
8
|
+
:SomosaguasSur=>"Somosaguas Sur|SSU|ML2",
|
9
|
+
:SomosaguasCentro=>"Somosaguas Centro|SCE|ML2",
|
10
|
+
:PozueloOeste=>"Pozuelo Oeste|PZO|ML2",
|
11
|
+
:Belgica=>"Bélgica|BLG|ML2",
|
12
|
+
:DosCastillas=>"Dos Castillas|DCS|ML2",
|
13
|
+
:CampusDeSomosaguas=>"Campus de Somosaguas|CSO|ML2",
|
14
|
+
:AvenidaDeEuropa=>"Avenida de Europa|AEU|ML2",
|
15
|
+
:Berna=>"Berna|BRN|ML2",
|
16
|
+
:EstacionDeAravaca=>"Estación de Aravaca|EAV|ML2",
|
17
|
+
:PuertaDeBoadilla=>"Puerta de Boadilla|PBO|ML3",
|
18
|
+
:InfanteDonLuis=>"Infante Don Luis|IDL|ML3",
|
19
|
+
:SigloXXI=>"Siglo XXI|SIX|ML3",
|
20
|
+
:NuevoMundo=>"Nuevo Mundo|NVM|ML3",
|
21
|
+
:BoadillaCentro=>"Boadilla Centro|BOC|ML3",
|
22
|
+
:FerialDeBoadilla=>"Ferial de Boadilla|FBO|ML3",
|
23
|
+
:Cantabria=>"Cantabria|CTB|ML3",
|
24
|
+
:PradoDelEspino=>"Prado del Espino|PES|ML3",
|
25
|
+
:VentorroDelCano=>"Ventorro del Cano|VCA|ML3",
|
26
|
+
:Monteprincipe=>"Montepríncipe|MNT|ML3",
|
27
|
+
:Retamares=>"Retamares|RTM|ML3",
|
28
|
+
:Cocheras=>"Cocheras|MLO|ML3",
|
29
|
+
:CiudadDelCine=>"Ciudad del Cine|CCI|ML3",
|
30
|
+
:JoseIsbert=>"José Isbert|JIS|ML3",
|
31
|
+
:CiudadDeLaImagen=>"Ciudad de la Imagen|CIM|ML3"
|
32
|
+
}
|
33
|
+
|
34
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diMLOrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- ariera
|
@@ -124,7 +124,7 @@ dependencies:
|
|
124
124
|
version: 2.3.0
|
125
125
|
name: rspec
|
126
126
|
version_requirements: *id007
|
127
|
-
description: This gem acts as an API to the MLO (Metro Ligero Oeste) public transportation of Madrid, allowing the user get
|
127
|
+
description: This gem acts as an API to the MLO (Metro Ligero Oeste) public transportation of Madrid, allowing the user get ETAs of the next 2 trains
|
128
128
|
email: ariera@gmail.com
|
129
129
|
executables: []
|
130
130
|
|
@@ -136,12 +136,16 @@ extra_rdoc_files:
|
|
136
136
|
files:
|
137
137
|
- .document
|
138
138
|
- .rspec
|
139
|
+
- .rvmrc
|
139
140
|
- Gemfile
|
141
|
+
- Gemfile.lock
|
140
142
|
- LICENSE.txt
|
141
143
|
- README.rdoc
|
142
144
|
- Rakefile
|
143
145
|
- VERSION
|
146
|
+
- diMLOrb.gemspec
|
144
147
|
- lib/diMLOrb.rb
|
148
|
+
- lib/stations.rb
|
145
149
|
- spec/diMLOrb_spec.rb
|
146
150
|
- spec/spec_helper.rb
|
147
151
|
has_rdoc: true
|