weather_fetcher 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36ae3bc84d954a730d42f83787961d04b3fdad94
4
- data.tar.gz: ea7802ca4db56e1a33d4586ec993615ad7594fe9
3
+ metadata.gz: 0e0b42eb8b3a0472d8eec2d0fdeb5340c2e6fd37
4
+ data.tar.gz: 136957f386ec94ab93299c6baddf994de4fe2eb3
5
5
  SHA512:
6
- metadata.gz: 5d89d9a57e5cf04a84c5cf9ec302927cf04a30645a2f50fa5c2dca536c0d46c5e41b48281bd52061710c3b7ebc1df137eee697be3f2c4457b94071656d5915e6
7
- data.tar.gz: f78d5c42bdee4420a8a9291a9dfb0b813e858c914724df621ca0fa3f52cc17e2aabca190f895bea4c85c45b619f186b3f7dfb5c0e0465c23745dcca3eff2a964
6
+ metadata.gz: 762ff6dd9c0277023a6e2ef8bb23bafd0d643dd7501902bc64cec51e2dcd3f2906db9c84d18575274367b387396f6645756c5b25bc3ad7e4d5bebdf9d78da96d
7
+ data.tar.gz: 114cd0b9e17def27edbce62bfab09139a1da064fd6616c28c860ff0054ce1a88c51ca0500fc9954217b63d4bfacaba7464dba18bac59c21241e8ce0b03fb5c0b
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -8,6 +8,8 @@ require 'providers/html_based/interia_pl'
8
8
  require 'providers/html_based/wp_pl'
9
9
  require 'providers/html_based/twoja_pogoda_pl'
10
10
  require 'providers/html_based/world_weather_online'
11
+ require 'providers/html_based/open_weather_map'
12
+ require 'providers/html_based/open_weather_map_forecast'
11
13
 
12
14
  require 'providers/metar_provider'
13
15
  require 'providers/metar/noaa'
@@ -0,0 +1,75 @@
1
+ #encoding: utf-8
2
+
3
+ require 'json'
4
+
5
+ module WeatherFetcher
6
+ class Provider::OpenWeatherMap < HtmlBasedProvider
7
+ def self.provider_name
8
+ "OpenWeatherMap"
9
+ end
10
+
11
+ # How often weather is updated
12
+ def self.weather_updated_every
13
+ 12*HOUR - 240
14
+ end
15
+
16
+ # This provider could use API key
17
+ # but this version won't
18
+ def self.api=(_api)
19
+ @@api = _api
20
+ end
21
+
22
+ def self.api
23
+ return nil unless defined?(@@api)
24
+ @@api
25
+ end
26
+
27
+ # Url for current provider
28
+ def url(p)
29
+ "http://api.openweathermap.org/data/2.5/weather?lat=#{p[:coords][:lat]}&lon=#{p[:coords][:lon]}&units=metric"
30
+ end
31
+
32
+ def can_fetch?(p)
33
+ begin
34
+ url(p).nil? == false
35
+ rescue
36
+ false
37
+ end
38
+ end
39
+
40
+ def process(string)
41
+ result = JSON.parse(string)
42
+
43
+ # fix for empty response
44
+ return if result.nil? or result["main"].nil? or result["main"]["temp"].nil?
45
+
46
+ current_time = Time.mktime(
47
+ Time.now.year,
48
+ Time.now.month,
49
+ Time.now.day,
50
+ Time.now.hour
51
+ )
52
+
53
+ h = {
54
+ :temperature => result["main"]["temp"].to_f,
55
+ :wind => result["wind"]["speed"].to_f,
56
+ :pressure => result["main"]["pressure"].to_f,
57
+ :rain => nil,
58
+ :snow => nil,
59
+ :provider => self.class.provider_name,
60
+
61
+ :cloud_cover => nil,
62
+ :humidity => result["main"]["humidity"].to_i,
63
+ :visibility => nil,
64
+
65
+ :wwo_type => :current,
66
+ :time_created => Time.now,
67
+ :time_from => current_time,
68
+ :time_to => current_time + 3600
69
+ }
70
+
71
+ return WeatherData.factory(h)
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,90 @@
1
+ #encoding: utf-8
2
+
3
+ require 'json'
4
+
5
+ module WeatherFetcher
6
+ class Provider::OpenWeatherMapForecast < HtmlBasedProvider
7
+ def self.provider_name
8
+ "OpenWeatherMap"
9
+ end
10
+
11
+ # How often weather is updated
12
+ def self.weather_updated_every
13
+ 12*HOUR - 240
14
+ end
15
+
16
+ # Url for current provider
17
+ def url(p)
18
+ "http://api.openweathermap.org/data/2.5/forecast/daily?lat=#{p[:coords][:lat]}&lon=#{p[:coords][:lon]}&cnt=15&mode=json&units=metric"
19
+ end
20
+
21
+ def can_fetch?(p)
22
+ begin
23
+ url(p).nil? == false
24
+ rescue
25
+ false
26
+ end
27
+ end
28
+
29
+ def process(string)
30
+ result = JSON.parse(string)
31
+
32
+ # fix for empty response
33
+ return if result.nil? or result["list"].nil?
34
+
35
+ current_time = Time.mktime(
36
+ Time.now.year,
37
+ Time.now.month,
38
+ Time.now.day,
39
+ Time.now.hour
40
+ )
41
+
42
+ weather_data = Array.new
43
+
44
+ result["list"].each do |w|
45
+ h_day = {
46
+ :temperature => w["temp"]["day"].to_f,
47
+ :wind => w["speed"].to_f,
48
+ :pressure => w["pressure"].to_f,
49
+ :rain => nil,
50
+ :snow => nil,
51
+ :provider => self.class.provider_name,
52
+
53
+ :cloud_cover => nil,
54
+ :humidity => w["humidity"].to_i,
55
+ :visibility => nil,
56
+
57
+ :wwo_type => :forecast,
58
+ :time_created => Time.now,
59
+ :time_from => Time.at(w["dt"].to_i - 6*HOUR),
60
+ :time_to => Time.at(w["dt"].to_i + 6*HOUR)
61
+ }
62
+
63
+ h_night = {
64
+ :temperature => w["temp"]["night"].to_f,
65
+ :wind => w["speed"].to_f,
66
+ :pressure => w["pressure"].to_f,
67
+ :rain => nil,
68
+ :snow => nil,
69
+ :provider => self.class.provider_name,
70
+
71
+ :cloud_cover => nil,
72
+ :humidity => w["humidity"].to_i,
73
+ :visibility => nil,
74
+
75
+ :wwo_type => :forecast,
76
+ :time_created => Time.now,
77
+ :time_from => Time.at(w["dt"].to_i + 6*HOUR),
78
+ :time_to => Time.at(w["dt"].to_i + 18*HOUR)
79
+ }
80
+
81
+ weather_data << h_day
82
+ weather_data << h_night
83
+ end
84
+
85
+
86
+ return WeatherData.factory(weather_data)
87
+ end
88
+
89
+ end
90
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weather_fetcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksander Kwiatkowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-25 00:00:00.000000000 Z
11
+ date: 2014-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curb
@@ -130,6 +130,8 @@ files:
130
130
  - lib/weather_fetcher/providers.rb
131
131
  - lib/weather_fetcher/providers/html_based/interia_pl.rb
132
132
  - lib/weather_fetcher/providers/html_based/onet_pl.rb
133
+ - lib/weather_fetcher/providers/html_based/open_weather_map.rb
134
+ - lib/weather_fetcher/providers/html_based/open_weather_map_forecast.rb
133
135
  - lib/weather_fetcher/providers/html_based/twoja_pogoda_pl.rb
134
136
  - lib/weather_fetcher/providers/html_based/world_weather_online.rb
135
137
  - lib/weather_fetcher/providers/html_based/wp_pl.rb