smn_ar 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 +18 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +9 -0
- data/lib/smn_ar.rb +8 -0
- data/lib/smn_ar/dominio/ciudad.rb +16 -0
- data/lib/smn_ar/dominio/pronostico.rb +66 -0
- data/lib/smn_ar/dominio/provincia.rb +15 -0
- data/lib/smn_ar/dominio/temperatura.rb +3 -0
- data/lib/smn_ar/scripts/scraper.rb +32 -0
- data/lib/smn_ar/version.rb +3 -0
- data/smn_ar.gemspec +26 -0
- data/spec/dominio/pronostico_spec.rb +28 -0
- data/spec/scripts/scraper_spec.rb +14 -0
- data/spec/spec_helper.rb +2 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f89213798656f9118ade7a381a6da695cb517182
|
4
|
+
data.tar.gz: 22fe472517d242cd472757c325169007d9a2e6bf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0892692beed7bdcf697a08be68e9a745885ddc29d1ba2ce0c1ade7f02c033c38d54693a01a9a42d9acd6dc12ce290f6c667239371b8cc859b66249641f7bd041
|
7
|
+
data.tar.gz: ee4f13907e6afff4bffdedb4024e43ca64beca2fe59468a597e03d69409e866fd47245764f8d01acc3293b25e5d9e555042bd3757212f974b3624501fdfc0c32
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p353
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Cristian Rasch
|
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,43 @@
|
|
1
|
+
# SmnAr
|
2
|
+
|
3
|
+
Esta gema expone el pronóstico meteorológico publicado publicado por el [Servicio Meteorológico Nacional](http://example.com/ "SMN") argentino
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'smn_ar'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install smn_ar
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require "smn_ar"
|
23
|
+
require "date"
|
24
|
+
|
25
|
+
pronostico = SmnAr::Pronostico.new(ciudad)
|
26
|
+
pronostico.temperatura_actual # => 32.4
|
27
|
+
temp = pronostico[Date.today] # pronóstico para hoy y los próximos tres días
|
28
|
+
temp.mimima # => 25
|
29
|
+
temp.maxima # => 37
|
30
|
+
pronostico[Date.today+4] # => nil
|
31
|
+
|
32
|
+
SmnAr::Ciudad.todas # => todas las ciudades del país soportadas
|
33
|
+
|
34
|
+
SmnAr::Provincia.todas # => todas las provincias del país soportadas
|
35
|
+
```
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/smn_ar.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative "../scripts/scraper"
|
2
|
+
|
3
|
+
module SmnAr
|
4
|
+
class Ciudad
|
5
|
+
attr_reader :provincia_id, :nombre_provincia, :nombre
|
6
|
+
|
7
|
+
def initialize(provincia_id, nombre_provincia, nombre)
|
8
|
+
@provincia_id = provincia_id.to_i
|
9
|
+
@nombre_provincia, @nombre = nombre_provincia, nombre
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.todas
|
13
|
+
@todas ||= Scraper.new.ciudades
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
require "open-uri"
|
3
|
+
require "uri"
|
4
|
+
require "date"
|
5
|
+
|
6
|
+
require_relative "temperatura"
|
7
|
+
|
8
|
+
module SmnAr
|
9
|
+
class Pronostico
|
10
|
+
URL = "http://www.smn.gov.ar/?mod=pron&id=:provincia_id&provincia=:nombre_provincia&ciudad=:nombre_ciudad".freeze
|
11
|
+
SELECTOR_TEMPERATURA_ACTUAL = "#divPronostico b".freeze
|
12
|
+
SELECTOR_TEMPERATURAS = "em:contains(':tipo')".freeze
|
13
|
+
REGEXP_TEMPERATURA = /\A(\d+) /
|
14
|
+
TEMP_MIN = "Mín".freeze
|
15
|
+
TEMP_MAX = "Máx".freeze
|
16
|
+
|
17
|
+
def initialize(ciudad)
|
18
|
+
@ciudad = ciudad
|
19
|
+
end
|
20
|
+
|
21
|
+
def temperatura_actual
|
22
|
+
@temperatura_actual ||= html.at_css(SELECTOR_TEMPERATURA_ACTUAL).text.to_f
|
23
|
+
end
|
24
|
+
|
25
|
+
def [](fecha)
|
26
|
+
pronosticos[fecha]
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def pronosticos
|
32
|
+
@pronosticos ||= begin
|
33
|
+
minimas = scrapear_temperaturas(TEMP_MIN)
|
34
|
+
maximas = scrapear_temperaturas(TEMP_MAX)
|
35
|
+
pronosticos, hoy = {}, Date.today
|
36
|
+
minimas.each_with_index do |minima, i|
|
37
|
+
pronosticos[hoy + i] = Temperatura.new(minima, maximas[i])
|
38
|
+
end
|
39
|
+
pronosticos
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def scrapear_temperaturas(tipo_temperatura)
|
44
|
+
nodos = html.css(SELECTOR_TEMPERATURAS.gsub(":tipo", tipo_temperatura))
|
45
|
+
temps = nodos.map { |nodo| nodo.parent.next.next.text[REGEXP_TEMPERATURA, 1] }
|
46
|
+
temps.compact!.map!(&:to_i)
|
47
|
+
end
|
48
|
+
|
49
|
+
def html
|
50
|
+
@html ||= begin
|
51
|
+
url = URL.gsub(":provincia_id", @ciudad.provincia_id.to_s).
|
52
|
+
gsub(":nombre_provincia", nombre_provincia).
|
53
|
+
gsub(":nombre_ciudad", nombre_ciudad)
|
54
|
+
Nokogiri::HTML(open(url))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def nombre_provincia
|
59
|
+
URI.encode(@ciudad.nombre_provincia)
|
60
|
+
end
|
61
|
+
|
62
|
+
def nombre_ciudad
|
63
|
+
URI.encode(@ciudad.nombre)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "open-uri"
|
2
|
+
require "uri"
|
3
|
+
|
4
|
+
require_relative "../dominio/provincia"
|
5
|
+
require_relative "../dominio/ciudad"
|
6
|
+
|
7
|
+
module SmnAr
|
8
|
+
class Scraper
|
9
|
+
URL = "http://www.smn.gov.ar/?mod=pron&id=2".freeze
|
10
|
+
REGEXP = /\?mod=pron&id=(\d+)&provincia=([^&]+)&ciudad=([^"]+)/
|
11
|
+
|
12
|
+
def ciudades
|
13
|
+
@ciudades ||= matches.map { |arr| Ciudad.new(*arr) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def provincias
|
17
|
+
@provincias ||= begin
|
18
|
+
arr = ciudades.map { |ciudad| [ciudad.provincia_id, ciudad.nombre_provincia] }.uniq!
|
19
|
+
arr.map! { |a| Provincia.new(*a) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def matches
|
26
|
+
@matches ||= begin
|
27
|
+
html = open(URL).read
|
28
|
+
html.scan(REGEXP)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/smn_ar.gemspec
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 'smn_ar/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "smn_ar"
|
8
|
+
spec.version = SmnAr::VERSION
|
9
|
+
spec.authors = ["Cristian Rasch"]
|
10
|
+
spec.email = ["cristianrasch@gmail.com"]
|
11
|
+
spec.description = %q{Wrapper para el pronóstico meteorológico publicado por http://www.smn.gov.ar}
|
12
|
+
spec.summary = %q{Esta gema expone el pronóstico meteorológico publicado publicado por el Servicio Meteorológico Nacional argentino (http://www.smn.gov.ar)}
|
13
|
+
spec.homepage = "https://github.com/wecodeio/smn_ar"
|
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_runtime_dependency "nokogiri"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "minitest", "~> 5.2.0"
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative "../spec_helper"
|
2
|
+
require File.expand_path("lib/smn_ar/dominio/pronostico")
|
3
|
+
require File.expand_path("lib/smn_ar/dominio/ciudad")
|
4
|
+
|
5
|
+
describe SmnAr::Pronostico do
|
6
|
+
let(:ciudad) { SmnAr::Ciudad.new(4, "Buenos Aires", "9 de Julio") }
|
7
|
+
subject { SmnAr::Pronostico.new(ciudad) }
|
8
|
+
|
9
|
+
it "scrapea la temperatura actual" do
|
10
|
+
subject.temperatura_actual.must_be :>, 0
|
11
|
+
end
|
12
|
+
|
13
|
+
it "scrapea el pronostico meteorológico para hoy" do
|
14
|
+
pronostico_para_hoy = subject[Date.today]
|
15
|
+
|
16
|
+
pronostico_para_hoy.wont_be_nil
|
17
|
+
pronostico_para_hoy.minima.must_be :>, 0
|
18
|
+
pronostico_para_hoy.maxima.must_be :>, 0
|
19
|
+
end
|
20
|
+
|
21
|
+
it "scrapea el pronostico meteorológico para mañana" do
|
22
|
+
pronostico_para_maniana = subject[Date.today + 1]
|
23
|
+
|
24
|
+
pronostico_para_maniana.wont_be_nil
|
25
|
+
pronostico_para_maniana.minima.must_be :>, 0
|
26
|
+
pronostico_para_maniana.maxima.must_be :>, 0
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative "../spec_helper"
|
2
|
+
require File.expand_path("lib/smn_ar/scripts/scraper")
|
3
|
+
|
4
|
+
describe SmnAr::Scraper do
|
5
|
+
subject { SmnAr::Scraper.new }
|
6
|
+
|
7
|
+
it "scrapea las provincias" do
|
8
|
+
subject.provincias.length.must_equal 24
|
9
|
+
end
|
10
|
+
|
11
|
+
it "scrapea las ciudades" do
|
12
|
+
subject.ciudades.wont_be_empty
|
13
|
+
end
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smn_ar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cristian Rasch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 5.2.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 5.2.0
|
69
|
+
description: Wrapper para el pronóstico meteorológico publicado por http://www.smn.gov.ar
|
70
|
+
email:
|
71
|
+
- cristianrasch@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .ruby-version
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/smn_ar.rb
|
83
|
+
- lib/smn_ar/dominio/ciudad.rb
|
84
|
+
- lib/smn_ar/dominio/pronostico.rb
|
85
|
+
- lib/smn_ar/dominio/provincia.rb
|
86
|
+
- lib/smn_ar/dominio/temperatura.rb
|
87
|
+
- lib/smn_ar/scripts/scraper.rb
|
88
|
+
- lib/smn_ar/version.rb
|
89
|
+
- smn_ar.gemspec
|
90
|
+
- spec/dominio/pronostico_spec.rb
|
91
|
+
- spec/scripts/scraper_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
homepage: https://github.com/wecodeio/smn_ar
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.0.14
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Esta gema expone el pronóstico meteorológico publicado publicado por el Servicio
|
117
|
+
Meteorológico Nacional argentino (http://www.smn.gov.ar)
|
118
|
+
test_files:
|
119
|
+
- spec/dominio/pronostico_spec.rb
|
120
|
+
- spec/scripts/scraper_spec.rb
|
121
|
+
- spec/spec_helper.rb
|