cetsp 0.1.0 → 0.1.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.
data/Rakefile CHANGED
@@ -17,8 +17,8 @@ Jeweler::Tasks.new do |gem|
17
17
  gem.name = "cetsp"
18
18
  gem.homepage = "http://github.com/pbalduino/cetsp"
19
19
  gem.license = "MIT"
20
- gem.summary = %Q{TODO: one-line summary of your gem}
21
- gem.description = %Q{TODO: longer description of your gem}
20
+ gem.summary = %Q{Returns data from cetsp.com.br in Ruby format}
21
+ gem.description = %Q{Returns data from cetsp.com.br in Ruby format}
22
22
  gem.email = "pbalduino+github@gmail.com"
23
23
  gem.authors = ["Plinio Balduino"]
24
24
  # dependencies defined in Gemfile
@@ -47,3 +47,4 @@ Rake::RDocTask.new do |rdoc|
47
47
  rdoc.rdoc_files.include('README*')
48
48
  rdoc.rdoc_files.include('lib/**/*.rb')
49
49
  end
50
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/cetsp.gemspec ADDED
@@ -0,0 +1,65 @@
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{cetsp}
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 = [%q{Plinio Balduino}]
12
+ s.date = %q{2011-10-22}
13
+ s.description = %q{Returns data from cetsp.com.br in Ruby format}
14
+ s.email = %q{pbalduino+github@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "cetsp.gemspec",
29
+ "lib/cetsp.rb",
30
+ "spec/cetsp_spec.rb",
31
+ "spec/sample/empty.html",
32
+ "spec/sample/ocorrencias.html",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/pbalduino/cetsp}
36
+ s.licenses = [%q{MIT}]
37
+ s.require_paths = [%q{lib}]
38
+ s.rubygems_version = %q{1.8.6}
39
+ s.summary = %q{Returns data from cetsp.com.br in Ruby format}
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
46
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
47
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
48
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
49
+ s.add_development_dependency(%q<rcov>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<nokogiri>, [">= 0"])
52
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
53
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
55
+ s.add_dependency(%q<rcov>, [">= 0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<nokogiri>, [">= 0"])
59
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
60
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
62
+ s.add_dependency(%q<rcov>, [">= 0"])
63
+ end
64
+ end
65
+
data/lib/cetsp.rb CHANGED
@@ -1,25 +1,23 @@
1
1
  # encoding UTF-8
2
2
 
3
3
  require 'nokogiri'
4
+ require 'open-uri'
4
5
 
5
6
  module CetSp
6
7
  class Parser
7
8
 
8
9
  def initialize(source)
9
- @parser = Nokogiri::HTML(open(source), nil, 'UTF-8')
10
+ puts source
11
+ @parser = Nokogiri::HTML(open(source), nil, 'ASCII-8BIT')
10
12
  @events = []
11
13
  end
12
14
 
13
15
  def parse
14
- rows = @parser.xpath('//body/center/table[2]/tr')
16
+ rows = @parser.search('tr.cor1', 'tr.cor2')
15
17
  rows.each do |row|
16
- begin
17
- @events << Event.new(:code => row.children[0].to_str.gsub(/\302\240/, ' ').strip.to_i,
18
- :place => row.children[2].to_str.gsub(/\302\240/, ' ').strip,
19
- :direction => row.children[4].to_str.gsub(/\302\240/, ' ').strip,
20
- :since => DateTime.strptime(row.children[6].to_str.gsub(/\302\240/, ' ').strip, "%d/%m/%y-%H:%M"))
21
- rescue
22
- end
18
+ @events << Event.new(:code => row.children[0].to_str.force_encoding("ASCII-8BIT").gsub(/\302\240/, ' ').strip.to_i,
19
+ :place => row.children[2].to_str.force_encoding("ASCII-8BIT").gsub(/\302\240/, ' ').strip,
20
+ :direction => row.children[4].to_str.force_encoding("ASCII-8BIT").gsub(/\302\240/, ' ').strip)
23
21
  end
24
22
  @events
25
23
  end
@@ -32,7 +30,6 @@ module CetSp
32
30
  @code = options[:code]
33
31
  @place = options[:place]
34
32
  @direction = options[:direction]
35
- @since = options[:since]
36
33
  end
37
34
  end
38
35
  end
data/spec/cetsp_spec.rb CHANGED
@@ -3,6 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  describe "Cetsp" do
4
4
 
5
5
  SOURCE = File.expand_path(File.dirname(__FILE__) + '/../spec/sample/ocorrencias.html')
6
+ EMPTY = File.expand_path(File.dirname(__FILE__) + '/../spec/sample/empty.html')
6
7
 
7
8
  before :each do
8
9
  @cetsp = CetSp::Parser.new(SOURCE)
@@ -13,7 +14,17 @@ describe "Cetsp" do
13
14
  end
14
15
 
15
16
  it "should return whatever" do
16
- p '---->', @cetsp.parse
17
+ @cetsp.parse.first.code.should == 206
18
+ end
19
+
20
+ it "should read an empty resource and return an empty array" do
21
+ @cetsp = CetSp::Parser.new(EMPTY)
22
+ @cetsp.parse.should == []
23
+
24
+ end
25
+
26
+ it "should work with real site" do
27
+ p CetSp::Parser.new("http://cetsp1.cetsp.com.br/monitransmapa/IMG10/ocorrencias.asp").parse
17
28
  end
18
29
 
19
30
  end
@@ -0,0 +1,149 @@
1
+
2
+ <html>
3
+ <head>
4
+ <META name=VI60_defaultClientScript content=VBScript>
5
+ <title>CET - Ocorr�ncias</title>
6
+
7
+ <style type="text/css">
8
+ <!--
9
+ BODY
10
+ {
11
+ FONT-SIZE: 10px;
12
+ COLOR: #000000;
13
+ FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
14
+ BACKGROUND-COLOR: #ffffff
15
+ }
16
+ H1
17
+ {
18
+ FONT-WEIGHT: bold;
19
+ FONT-SIZE: 17px;
20
+ COLOR: #000000;
21
+ FONT-STYLE: normal;
22
+ FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
23
+ }
24
+ H2
25
+ {
26
+ FONT-WEIGHT: bold;
27
+ FONT-SIZE: 15px;
28
+ COLOR: #000000;
29
+ FONT-STYLE: normal;
30
+ FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
31
+ }
32
+ H3
33
+ {
34
+ FONT-WEIGHT: bold;
35
+ FONT-SIZE: 14px;
36
+ COLOR: brown;
37
+ FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
38
+ }
39
+ H4
40
+ {
41
+ FONT-WEIGHT: bold;
42
+ FONT-SIZE: 12px;
43
+ COLOR: #0033cc;
44
+ FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
45
+ }
46
+ TH
47
+ {
48
+ FONT-WEIGHT: bold;
49
+ FONT-SIZE: 11px;
50
+ COLOR: #ffffff;
51
+ FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
52
+ BACKGROUND-COLOR: #003366
53
+ }
54
+ TABLE
55
+ {
56
+ BORDER-RIGHT: #ffffff 1px solid;
57
+ BORDER-TOP: #ffffff 1px solid;
58
+ FONT-SIZE: 10px;
59
+ BORDER-LEFT: #ffffff 1px solid;
60
+ COLOR: #000000;
61
+ BORDER-BOTTOM: #ffffff 1px solid;
62
+ FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
63
+ }
64
+ TR
65
+ {
66
+ VERTICAL-ALIGN: middle;
67
+ TEXT-ALIGN: left
68
+ }
69
+ .cor1 {
70
+ BACKGROUND-COLOR: #eaeaea
71
+ }
72
+ .cor2 {
73
+ BACKGROUND-COLOR: #dbdbdb
74
+ }
75
+ -->
76
+ </style>
77
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
78
+ <meta http-equiv="Pragma" content="no-cache">
79
+
80
+
81
+ <script language=javascript>
82
+
83
+ function Abre(ordem) {
84
+ if (ordem=="C")
85
+ { window.open ("ocorrencias.asp?ordem=C", "_self","");}
86
+ if (ordem=="H")
87
+ { window.open ("ocorrenciasH.asp?ordem=H", "_self","");}
88
+ }
89
+
90
+ </script>
91
+
92
+ </head>
93
+
94
+ <body>
95
+
96
+
97
+ <style type="text/css">
98
+ <!--
99
+ .barra {
100
+ font-family: Verdana, Tahoma, Arial;
101
+ font-weight: normal;
102
+ color: #FFFFCC;
103
+ font-size: 10px;
104
+ }
105
+ -->
106
+ </style>
107
+
108
+ <script language=javascript>
109
+ function OpenWindow( pagina, largura, altura, janela )
110
+ {
111
+ window.status = "";
112
+
113
+ strFeatures = "top=100,left=200,width=" + largura + ",height=" + altura + ",toolbar=no,"
114
+ + "menubar=no,location=no,directories=no,resizable=1,status=no,scrollbars=1";
115
+ objNewWindow = window.open(pagina ,janela , strFeatures);
116
+ objNewWindow.focus()
117
+ }
118
+
119
+ </script>
120
+
121
+ <div id="Layer1" style="position:absolute; width:200px; height:30px; z-index:1; left:100px; top: 4px;"><img src="http://cetsp1.cetsp.com.br/monitransmapa/agora/barra.gif" width="590" height="30">
122
+ <div id="hora" style="position:absolute; width:52px; height:19px; z-index:2; left: 83px; top: 9px; visibility: inherit;" class="barra"><b>15:49</b></div>
123
+ <!--div id="lentidao" style="position:absolute; width:52px; height:19px; z-index:2; left: 213px; top: 8px; visibility: inherit;" class="barra"><b>9132</b> km</div-->
124
+ <div id="lentidao" style="position:absolute; width:52px; height:19px; z-index:2; left: 210px; top: 8px; visibility: inherit;" class="barra"><b>1,1%</b></div>
125
+ <div id="tendencia" style="position:absolute; width:52px; height:19px; z-index:2; left: 319px; top: 10px; visibility: inherit;" class="barra"><img src="http://cetsp1.cetsp.com.br/monitransmapa/agora/img/BAIXA.gif" alt="BAIXA"></div>
126
+ <div id="bTendencias" style="position:absolute; width:31px; height:23px; z-index:1; left: 401px; top: 6px; cursor:hand"><a href="javascript:OpenWindow('http://cetsp1.cetsp.com.br/monitransmapa/IMG2/eixos.asp', '790', '440','eixos')"><img src="http://cetsp1.cetsp.com.br/monitransmapa/agora/img/bTendencia.jpg" width="27" height="21" border="0" title="Tend�ncia por Eixo"></a></div>
127
+ <div id="bGraficos" style="position:absolute; width:31px; height:23px; z-index:1; left: 434px; top: 6px; cursor:hand"><a href="javascript:OpenWindow('http://cetsp1.cetsp.com.br/monitransmapa/agora/graficolimite.asp', '760', '535', 'grafico')"><img src="http://cetsp1.cetsp.com.br/monitransmapa/agora/img/bGraficos.jpg" width="27" height="21" border="0" title="Gr�fico de Lentid�o"></a></div>
128
+ <div id="bLentidoes" style="position:absolute; width:31px; height:23px; z-index:1; left: 466px; top: 6px; cursor:hand"><a href="javascript:OpenWindow('http://cetsp1.cetsp.com.br/monitransmapa/IMG2/lentidao.asp', '790', '600', 'lentidao')"><img src="http://cetsp1.cetsp.com.br/monitransmapa/agora/img/bLentidao.jpg" width="27" height="21" border="0" title="Lentid�o por Corredor"></a></div>
129
+ <div id="bOcorrencias" style="position:absolute; width:31px; height:23px; z-index:1; left: 498px; top: 6px; cursor:hand"><a href="javascript:OpenWindow('http://cetsp1.cetsp.com.br/monitransmapa/IMG2/ocorrencias.asp', '790', '600', 'ocorrencias')"><img src="http://cetsp1.cetsp.com.br/monitransmapa/agora/img/bOcorrencias.jpg" width="27" height="21" border="0" title="Ocorr�ncias"></a></div>
130
+
131
+ <div id="bAjuda" style="position:absolute; width:31px; height:23px; z-index:1; left: 562px; top: 6px; cursor:hand"><a href="javascript:OpenWindow('http://cetsp1.cetsp.com.br/monitransmapa/agora/ajuda.htm', '790', '600', 'ajuda')"><img src="http://cetsp1.cetsp.com.br/monitransmapa/agora/img/bAjuda.jpg" width="27" height="21" border="0" title="Ajuda"></a></div>
132
+ </div>
133
+
134
+
135
+ <center>
136
+ <br>
137
+ <br>
138
+ <h3>Ocorr�ncias</h3>
139
+
140
+
141
+ <table style="position:absolute; top:10; left:12" cellpadding=0>
142
+ <tr><td>Ordem:</td></tr>
143
+ <tr><td><input type=radio name=optOrdem value="C" style="position:relative; top:3" checked onclick="javascript:Abre('C')">C�digo</td></tr>
144
+ <tr><td><input type=radio name=optOrdem value="H" style="position:relative; top:3" onclick="javascript:Abre('H')">In�cio</td></tr>
145
+ </table>
146
+
147
+ </body>
148
+ </HTML>
149
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cetsp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-10-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &72515690 !ruby/object:Gem::Requirement
16
+ requirement: &83918410 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *72515690
24
+ version_requirements: *83918410
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &72515450 !ruby/object:Gem::Requirement
27
+ requirement: &83917990 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.3.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *72515450
35
+ version_requirements: *83917990
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &72514980 !ruby/object:Gem::Requirement
38
+ requirement: &83917190 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *72514980
46
+ version_requirements: *83917190
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &72514170 !ruby/object:Gem::Requirement
49
+ requirement: &83916300 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *72514170
57
+ version_requirements: *83916300
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &72513310 !ruby/object:Gem::Requirement
60
+ requirement: &83915600 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *72513310
68
+ version_requirements: *83915600
69
69
  description: Returns data from cetsp.com.br in Ruby format
70
70
  email: pbalduino+github@gmail.com
71
71
  executables: []
@@ -82,8 +82,10 @@ files:
82
82
  - README.rdoc
83
83
  - Rakefile
84
84
  - VERSION
85
+ - cetsp.gemspec
85
86
  - lib/cetsp.rb
86
87
  - spec/cetsp_spec.rb
88
+ - spec/sample/empty.html
87
89
  - spec/sample/ocorrencias.html
88
90
  - spec/spec_helper.rb
89
91
  homepage: http://github.com/pbalduino/cetsp