meteoub-gem 0.1.0
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/.document +5 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +53 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +9 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/bin/meteoub +12 -0
- data/lib/meteoub-gem.rb +120 -0
- data/test/helper.rb +18 -0
- data/test/test_meteoub-gem.rb +7 -0
- metadata +175 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "activerecord"
|
7
|
+
gem "json"
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "shoulda", ">= 0"
|
13
|
+
# gem "rdoc", "~> 3.12"
|
14
|
+
gem "rdoc"
|
15
|
+
# gem "bundler", "~> 1.0.0"
|
16
|
+
gem "bundler"
|
17
|
+
gem "jeweler", "~> 1.8.4"
|
18
|
+
gem "rcov", ">= 0"
|
19
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.2.13)
|
5
|
+
activesupport (= 3.2.13)
|
6
|
+
builder (~> 3.0.0)
|
7
|
+
activerecord (3.2.13)
|
8
|
+
activemodel (= 3.2.13)
|
9
|
+
activesupport (= 3.2.13)
|
10
|
+
arel (~> 3.0.2)
|
11
|
+
tzinfo (~> 0.3.29)
|
12
|
+
activesupport (3.2.13)
|
13
|
+
i18n (= 0.6.1)
|
14
|
+
multi_json (~> 1.0)
|
15
|
+
arel (3.0.2)
|
16
|
+
bourne (1.4.0)
|
17
|
+
mocha (~> 0.13.2)
|
18
|
+
builder (3.0.4)
|
19
|
+
git (1.2.5)
|
20
|
+
i18n (0.6.1)
|
21
|
+
jeweler (1.8.4)
|
22
|
+
bundler (~> 1.0)
|
23
|
+
git (>= 1.2.5)
|
24
|
+
rake
|
25
|
+
rdoc
|
26
|
+
json (1.7.7)
|
27
|
+
metaclass (0.0.1)
|
28
|
+
mocha (0.13.3)
|
29
|
+
metaclass (~> 0.0.1)
|
30
|
+
multi_json (1.7.2)
|
31
|
+
rake (10.0.4)
|
32
|
+
rcov (1.0.0)
|
33
|
+
rdoc (4.0.0)
|
34
|
+
shoulda (3.4.0)
|
35
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
36
|
+
shoulda-matchers (~> 1.0, >= 1.4.1)
|
37
|
+
shoulda-context (1.0.2)
|
38
|
+
shoulda-matchers (1.5.4)
|
39
|
+
activesupport (>= 3.0.0)
|
40
|
+
bourne (~> 1.3)
|
41
|
+
tzinfo (0.3.37)
|
42
|
+
|
43
|
+
PLATFORMS
|
44
|
+
ruby
|
45
|
+
|
46
|
+
DEPENDENCIES
|
47
|
+
activerecord
|
48
|
+
bundler
|
49
|
+
jeweler (~> 1.8.4)
|
50
|
+
json
|
51
|
+
rcov
|
52
|
+
rdoc
|
53
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Josep
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "meteoub-gem"
|
18
|
+
gem.homepage = "http://github.com/apuratepp/meteoub-gem"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A rewrite of the MeteoUB library wich gets, parses and stores weather data from infomet.am.ub.es}
|
21
|
+
gem.description = %Q{A rewrite of the MeteoUB library wich gets, parses and stores weather data from infomet.am.ub.es}
|
22
|
+
gem.email = "apuratepp@gmail.com"
|
23
|
+
gem.authors = ["Josep"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rdoc/task'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "meteoub-gem #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/meteoub
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
4
|
+
|
5
|
+
require 'meteoub-gem'
|
6
|
+
|
7
|
+
# DB_PATH = File.join(File.dirname(__FILE__), '..', 'db', 'meteo_ub.sqlite3')
|
8
|
+
# ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => DB_PATH)
|
9
|
+
# MeteoUB::MeasureTable.up unless ActiveRecord::Base.connection.table_exists? :measures
|
10
|
+
|
11
|
+
dades = MeteoUB::Data.new
|
12
|
+
p dades.temperature
|
data/lib/meteoub-gem.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'date'
|
3
|
+
require 'active_record'
|
4
|
+
|
5
|
+
module MeteoUB
|
6
|
+
DATA_URL = 'http://infomet.am.ub.es/campbell/www.dat'
|
7
|
+
|
8
|
+
class Data
|
9
|
+
attr_accessor :data_uri
|
10
|
+
attr_accessor :raw_data
|
11
|
+
|
12
|
+
attr_accessor :datetime
|
13
|
+
attr_accessor :temperature
|
14
|
+
attr_accessor :pressure
|
15
|
+
attr_accessor :humidity
|
16
|
+
attr_accessor :sunrise
|
17
|
+
attr_accessor :sunset
|
18
|
+
attr_accessor :rain
|
19
|
+
attr_accessor :precipitation
|
20
|
+
attr_accessor :max_wind_speed
|
21
|
+
attr_accessor :max_wind_speed_km_h
|
22
|
+
attr_accessor :windrose
|
23
|
+
|
24
|
+
def initialize(params = {})
|
25
|
+
@data_uri = URI(DATA_URL)
|
26
|
+
parse if get
|
27
|
+
end
|
28
|
+
|
29
|
+
def get
|
30
|
+
@raw_data = Net::HTTP.get(@data_uri).split("\n")
|
31
|
+
true
|
32
|
+
rescue
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
36
|
+
def parse
|
37
|
+
@datetime = DateTime.strptime(@raw_data[0] + " " + @raw_data[1] + " UTC", "%d-%m-%y %k:%M %Z")
|
38
|
+
@temperature = @raw_data[2].to_f
|
39
|
+
@pressure = @raw_data[10].to_f
|
40
|
+
@humidity = @raw_data[7].to_f
|
41
|
+
@sunrise = parse_date(@raw_data[19])
|
42
|
+
@sunset = parse_date(@raw_data[20])
|
43
|
+
@rain = @raw_data[22].to_i == 1
|
44
|
+
@precipitation = @raw_data[21].to_i
|
45
|
+
@max_wind_speed = @raw_data[12].to_f
|
46
|
+
@max_wind_speed_km_h = @max_wind_speed * 3.6
|
47
|
+
@windrose = parse_windrose(@raw_data[13].to_f)
|
48
|
+
end
|
49
|
+
|
50
|
+
def parse_date(date_raw)
|
51
|
+
hour, minutes = date_raw.split(":")
|
52
|
+
if minutes == 60
|
53
|
+
minutes = 0
|
54
|
+
hour += 1
|
55
|
+
end
|
56
|
+
DateTime.strptime(@raw_data[0] + " #{hour}:#{minutes} UTC", "%d-%m-%y %k:%M %Z")
|
57
|
+
end
|
58
|
+
|
59
|
+
# http://cbc.riocean.com/wstat/012006rose.html
|
60
|
+
def parse_windrose(windrose_raw)
|
61
|
+
case(windrose_raw)
|
62
|
+
when (0..11.25)
|
63
|
+
return "N"
|
64
|
+
when (11.26..33.75)
|
65
|
+
return "NNE"
|
66
|
+
when (33.76..56.25)
|
67
|
+
return "NE"
|
68
|
+
when (56.26..78.75)
|
69
|
+
return "ENE"
|
70
|
+
when (78.76..101.25)
|
71
|
+
return "E"
|
72
|
+
when (101.26..123.75)
|
73
|
+
return "ESE"
|
74
|
+
when (123.76..146.25)
|
75
|
+
return "SE"
|
76
|
+
when (146.26..168.75)
|
77
|
+
return "SSE"
|
78
|
+
when (168.76..191.25)
|
79
|
+
return "S"
|
80
|
+
when (191.16..213.75)
|
81
|
+
return "SSW"
|
82
|
+
when (213.76..236.25)
|
83
|
+
return "SW"
|
84
|
+
when (236.26..258.75)
|
85
|
+
return "WSW"
|
86
|
+
when (258.76..281.25)
|
87
|
+
return "W"
|
88
|
+
when (281.26..303.75)
|
89
|
+
return "WNW"
|
90
|
+
when (303.76..326.25)
|
91
|
+
return "NW"
|
92
|
+
when (326.26..348.75)
|
93
|
+
return "NNW"
|
94
|
+
when (348.76..360.0)
|
95
|
+
return "N"
|
96
|
+
else
|
97
|
+
return "???"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def save
|
102
|
+
measure = Measure.new({:datetime => @datetime, :temperature => @temperature})
|
103
|
+
measure.save
|
104
|
+
end
|
105
|
+
end
|
106
|
+
class Measure < ActiveRecord::Base
|
107
|
+
end
|
108
|
+
class MeasureTable < ActiveRecord::Migration
|
109
|
+
def self.up
|
110
|
+
create_table :measures do |t|
|
111
|
+
t.datetime :datetime
|
112
|
+
t.float :temperature
|
113
|
+
t.timestamps
|
114
|
+
end
|
115
|
+
end
|
116
|
+
def self.down
|
117
|
+
drop_table :measures
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'meteoub-gem'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: meteoub-gem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Josep
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-03-28 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 3
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
version_requirements: *id001
|
31
|
+
name: activerecord
|
32
|
+
prerelease: false
|
33
|
+
type: :runtime
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
hash: 3
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
version_requirements: *id002
|
45
|
+
name: json
|
46
|
+
prerelease: false
|
47
|
+
type: :runtime
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 3
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
version_requirements: *id003
|
59
|
+
name: shoulda
|
60
|
+
prerelease: false
|
61
|
+
type: :development
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
version_requirements: *id004
|
73
|
+
name: rdoc
|
74
|
+
prerelease: false
|
75
|
+
type: :development
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
version_requirements: *id005
|
87
|
+
name: bundler
|
88
|
+
prerelease: false
|
89
|
+
type: :development
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
hash: 63
|
97
|
+
segments:
|
98
|
+
- 1
|
99
|
+
- 8
|
100
|
+
- 4
|
101
|
+
version: 1.8.4
|
102
|
+
version_requirements: *id006
|
103
|
+
name: jeweler
|
104
|
+
prerelease: false
|
105
|
+
type: :development
|
106
|
+
- !ruby/object:Gem::Dependency
|
107
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
hash: 3
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
version: "0"
|
116
|
+
version_requirements: *id007
|
117
|
+
name: rcov
|
118
|
+
prerelease: false
|
119
|
+
type: :development
|
120
|
+
description: A rewrite of the MeteoUB library wich gets, parses and stores weather data from infomet.am.ub.es
|
121
|
+
email: apuratepp@gmail.com
|
122
|
+
executables:
|
123
|
+
- meteoub
|
124
|
+
extensions: []
|
125
|
+
|
126
|
+
extra_rdoc_files:
|
127
|
+
- LICENSE.txt
|
128
|
+
- README.rdoc
|
129
|
+
files:
|
130
|
+
- .document
|
131
|
+
- Gemfile
|
132
|
+
- Gemfile.lock
|
133
|
+
- LICENSE.txt
|
134
|
+
- README.rdoc
|
135
|
+
- Rakefile
|
136
|
+
- VERSION
|
137
|
+
- bin/meteoub
|
138
|
+
- lib/meteoub-gem.rb
|
139
|
+
- test/helper.rb
|
140
|
+
- test/test_meteoub-gem.rb
|
141
|
+
homepage: http://github.com/apuratepp/meteoub-gem
|
142
|
+
licenses:
|
143
|
+
- MIT
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
none: false
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
hash: 3
|
155
|
+
segments:
|
156
|
+
- 0
|
157
|
+
version: "0"
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
none: false
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
hash: 3
|
164
|
+
segments:
|
165
|
+
- 0
|
166
|
+
version: "0"
|
167
|
+
requirements: []
|
168
|
+
|
169
|
+
rubyforge_project:
|
170
|
+
rubygems_version: 1.8.24
|
171
|
+
signing_key:
|
172
|
+
specification_version: 3
|
173
|
+
summary: A rewrite of the MeteoUB library wich gets, parses and stores weather data from infomet.am.ub.es
|
174
|
+
test_files: []
|
175
|
+
|