weather_fetcher 0.1.0 → 0.1.1

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: c4e125667ec4f19310d5d5fd67f808d78b0c8f22
4
- data.tar.gz: 0f5834b7b8bbea71bc4ce3ac3e57b0fd2aa8110f
3
+ metadata.gz: 36ae3bc84d954a730d42f83787961d04b3fdad94
4
+ data.tar.gz: ea7802ca4db56e1a33d4586ec993615ad7594fe9
5
5
  SHA512:
6
- metadata.gz: 9800629a7cefc2f5f8ee4e0c808ae9aad1ad1b6b4fe1fff3d556443a12cef3dc9aa7db534189a2c7cc1970e249dfc3b7dbad160003c92492c7a13f6e1822d74f
7
- data.tar.gz: bf7c4406acea6b09332b217d89bc1374b59cd0fb9177072db9eac8e7dabdf1a513101fa874e9e993ff7c86dfa2b9df4a4e941990195ea1aac941d50ba8c7e350
6
+ metadata.gz: 5d89d9a57e5cf04a84c5cf9ec302927cf04a30645a2f50fa5c2dca536c0d46c5e41b48281bd52061710c3b7ebc1df137eee697be3f2c4457b94071656d5915e6
7
+ data.tar.gz: f78d5c42bdee4420a8a9291a9dfb0b813e858c914724df621ca0fa3f52cc17e2aabca190f895bea4c85c45b619f186b3f7dfb5c0e0465c23745dcca3eff2a964
data/Gemfile.lock CHANGED
@@ -1,65 +1,72 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- addressable (2.3.5)
4
+ addressable (2.3.6)
5
5
  builder (3.2.2)
6
- curb (0.8.5)
6
+ curb (0.8.6)
7
+ descendants_tracker (0.0.4)
8
+ thread_safe (~> 0.3, >= 0.3.1)
7
9
  diff-lcs (1.2.5)
8
- docile (1.1.1)
9
- faraday (0.8.8)
10
- multipart-post (~> 1.2.0)
11
- git (1.2.6)
12
- github_api (0.10.1)
13
- addressable
14
- faraday (~> 0.8.1)
15
- hashie (>= 1.2)
16
- multi_json (~> 1.4)
17
- nokogiri (~> 1.5.2)
10
+ docile (1.1.5)
11
+ faraday (0.9.0)
12
+ multipart-post (>= 1.2, < 3)
13
+ git (1.2.8)
14
+ github_api (0.12.2)
15
+ addressable (~> 2.3)
16
+ descendants_tracker (~> 0.0.4)
17
+ faraday (~> 0.8, < 0.10)
18
+ hashie (>= 3.3)
19
+ multi_json (>= 1.7.5, < 2.0)
20
+ nokogiri (~> 1.6.3)
18
21
  oauth2
19
- hashie (2.0.5)
20
- highline (1.6.20)
21
- httpauth (0.2.0)
22
- jeweler (1.8.8)
22
+ hashie (3.3.2)
23
+ highline (1.6.21)
24
+ jeweler (2.0.1)
23
25
  builder
24
- bundler (~> 1.0)
26
+ bundler (>= 1.0)
25
27
  git (>= 1.2.5)
26
- github_api (= 0.10.1)
28
+ github_api
27
29
  highline (>= 1.6.15)
28
- nokogiri (= 1.5.10)
30
+ nokogiri (>= 1.5.10)
29
31
  rake
30
32
  rdoc
31
33
  json (1.8.1)
32
- jwt (0.1.8)
33
- multi_json (>= 1.5)
34
- multi_json (1.8.2)
34
+ jwt (1.2.0)
35
+ mini_portile (0.6.1)
36
+ multi_json (1.10.1)
35
37
  multi_xml (0.5.5)
36
- multipart-post (1.2.0)
37
- nokogiri (1.5.10)
38
- oauth2 (0.9.2)
39
- faraday (~> 0.8)
40
- httpauth (~> 0.2)
41
- jwt (~> 0.1.4)
42
- multi_json (~> 1.0)
38
+ multipart-post (2.0.0)
39
+ nokogiri (1.6.5)
40
+ mini_portile (~> 0.6.0)
41
+ oauth2 (1.0.0)
42
+ faraday (>= 0.8, < 0.10)
43
+ jwt (~> 1.0)
44
+ multi_json (~> 1.3)
43
45
  multi_xml (~> 0.5)
44
46
  rack (~> 1.2)
45
- rack (1.5.2)
46
- rake (10.1.1)
47
- rdoc (4.0.1)
47
+ rack (1.6.0)
48
+ rake (10.4.2)
49
+ rdoc (4.2.0)
48
50
  json (~> 1.4)
49
- rspec (2.14.1)
50
- rspec-core (~> 2.14.0)
51
- rspec-expectations (~> 2.14.0)
52
- rspec-mocks (~> 2.14.0)
53
- rspec-core (2.14.7)
54
- rspec-expectations (2.14.4)
55
- diff-lcs (>= 1.1.3, < 2.0)
56
- rspec-mocks (2.14.4)
51
+ rspec (3.1.0)
52
+ rspec-core (~> 3.1.0)
53
+ rspec-expectations (~> 3.1.0)
54
+ rspec-mocks (~> 3.1.0)
55
+ rspec-core (3.1.7)
56
+ rspec-support (~> 3.1.0)
57
+ rspec-expectations (3.1.2)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.1.0)
60
+ rspec-mocks (3.1.3)
61
+ rspec-support (~> 3.1.0)
62
+ rspec-support (3.1.2)
57
63
  simple_metar_parser (0.0.1)
58
- simplecov (0.8.2)
64
+ simplecov (0.9.1)
59
65
  docile (~> 1.1.0)
60
- multi_json
66
+ multi_json (~> 1.0)
61
67
  simplecov-html (~> 0.8.0)
62
68
  simplecov-html (0.8.0)
69
+ thread_safe (0.3.4)
63
70
 
64
71
  PLATFORMS
65
72
  ruby
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -6,6 +6,7 @@ require 'providers/html_based_provider'
6
6
  require 'providers/html_based/onet_pl'
7
7
  require 'providers/html_based/interia_pl'
8
8
  require 'providers/html_based/wp_pl'
9
+ require 'providers/html_based/twoja_pogoda_pl'
9
10
  require 'providers/html_based/world_weather_online'
10
11
 
11
12
  require 'providers/metar_provider'
@@ -0,0 +1,112 @@
1
+ #encoding: utf-8
2
+
3
+ require 'nokogiri'
4
+ require 'time'
5
+
6
+ module WeatherFetcher
7
+ class Provider::TwojaPogodaPl < HtmlBasedProvider
8
+
9
+ def self.provider_name
10
+ "TwojaPogoda.pl"
11
+ end
12
+
13
+ def process(string)
14
+ return WeatherData.factory(_process(string))
15
+ end
16
+
17
+ # Process response body and rip out weather data
18
+ def _process(body_raw)
19
+ data = Array.new
20
+ b = Nokogiri::HTML(body_raw)
21
+
22
+ dates = b.css("table.items > tr > th > small")
23
+ dates = dates.collect { |d| Time.parse(d.children.first.to_s) }
24
+
25
+ temperatures = Array.new
26
+ winds = Array.new
27
+ clouds = Array.new
28
+ feel_temps = Array.new
29
+ humids = Array.new
30
+ pressures = Array.new
31
+ precips = Array.new
32
+
33
+ rows = b.css("table.items > tr")
34
+ rows.each do |row|
35
+ tags = row.css("td > div")
36
+ tags.each_with_index do |tag, i|
37
+ if tag.attribute("class").to_s == "info"
38
+ temperatures << tag.css("strong").children.first.to_s.to_f
39
+ end
40
+
41
+ if tag.children.first.to_s == "Wiatr"
42
+ wind = tags[i + 1].children.first.to_s.to_f
43
+ winds << wind
44
+ end
45
+
46
+ if tag.children.first.to_s == "Chmury"
47
+ cloud = tags[i + 1].children.first.to_s
48
+ if cloud =~ /(\d{1,2})-(\d{1,2})/
49
+ cloud = ($1.to_i + $2.to_i) / 2
50
+ elsif cloud =~ /(\d{1,2}) /
51
+ cloud = $1.to_i
52
+ else
53
+ cloud = nil
54
+ end
55
+ clouds << cloud
56
+ end
57
+
58
+ if tag.children.first.to_s == "T.odczuw."
59
+ feel_temp = tags[i + 1].children.first.to_s.to_f
60
+ feel_temps << feel_temp
61
+ end
62
+
63
+ if tag.children.first.to_s == "Wilgotność"
64
+ humid = tags[i + 1].children.first.to_s.to_f
65
+ humids << humid
66
+ end
67
+
68
+ if tag.children.first.to_s == "Ciśnienie"
69
+ pressure = tags[i + 1].children.first.to_s.to_f
70
+ pressures << pressure
71
+ end
72
+
73
+ if tag.children.first.to_s == "Opady"
74
+ precip = tags[i + 1].children.first.to_s
75
+ if precip =~ /(\d{1,2}\.?\d{1,2})/
76
+ precip = $1.to_f
77
+ else
78
+ precip = nil
79
+ end
80
+ precips << precip
81
+ end
82
+
83
+ end
84
+ end
85
+
86
+ dates.each_with_index do |d, i|
87
+ data << {
88
+ :time_created => Time.now,
89
+ :time_from => d,
90
+ :time_to => d + 24*3600,
91
+ :temperature => temperatures[i],
92
+ :feel_temperature => feel_temps[i],
93
+ :pressure => pressures[i],
94
+ :wind_kmh => winds[i],
95
+ :wind => winds[i] / 3.6,
96
+ # :snow => nil, #snows[0][0].to_f,
97
+ :rain => precips[i],
98
+ :cloud_cover => clouds[i],
99
+ :humidity => humids[i],
100
+ :provider => self.class.provider_name
101
+ }
102
+ end
103
+
104
+ # puts data.inspect
105
+
106
+ return data
107
+ end
108
+
109
+
110
+ end
111
+
112
+ end
@@ -25,7 +25,6 @@ module WeatherFetcher
25
25
 
26
26
  # Url for current provider
27
27
  def url(p)
28
- #"http://free.worldweatheronline.com/feed/weather.ashx?key=#{@@api}&q=#{p[:coords][:lat]},#{p[:coords][:lon]}&num_of_days=2&format=json"
29
28
  "http://api.worldweatheronline.com/free/v1/weather.ashx?q=#{p[:coords][:lat]},#{p[:coords][:lon]}&format=json&num_of_days=5&key=#{@@api}"
30
29
  end
31
30
 
@@ -65,38 +64,41 @@ module WeatherFetcher
65
64
 
66
65
  # prediction
67
66
  predictions = result["data"]["weather"]
68
- predictions.each do |p|
69
- h = process_node(p)
67
+ # example, there is no prediction on Antarctica
68
+ if predictions and predictions.kind_of?(Array)
69
+ predictions.each do |p|
70
+ h = process_node(p)
71
+
72
+ # is always 0
73
+ [:pressure, :cloud_cover, :humidity, :visibility].each do |k|
74
+ h.delete(k)
75
+ end
76
+
77
+ # create 2 records using tempMinC and tempMaxC
78
+ hl = h.clone.merge(
79
+ {
80
+ :wwo_type => :prediction_temp_low,
81
+ :time_created => Time.now,
82
+ :time_from => Time.create_time_from_string(p["date"], "0:00") - 4 * 3600,
83
+ :time_to => Time.create_time_from_string(p["date"], "0:00") + 8 * 3600,
84
+ :temperature => p["tempMinC"].to_i
85
+ }
86
+ )
87
+ weather_archives << hl
88
+
89
+ # and high
90
+ hh = h.clone.merge(
91
+ {
92
+ :wwo_type => :prediction_temp_high,
93
+ :time_created => Time.now,
94
+ :time_from => Time.create_time_from_string(p["date"], "0:00") + 8 * 3600,
95
+ :time_to => Time.create_time_from_string(p["date"], "0:00") + 20 * 3600,
96
+ :temperature => p["tempMaxC"].to_i
97
+ }
98
+ )
99
+ weather_archives << hh
70
100
 
71
- # is always 0
72
- [:pressure, :cloud_cover, :humidity, :visibility].each do |k|
73
- h.delete(k)
74
101
  end
75
-
76
- # create 2 records using tempMinC and tempMaxC
77
- hl = h.clone.merge(
78
- {
79
- :wwo_type => :prediction_temp_low,
80
- :time_created => Time.now,
81
- :time_from => Time.create_time_from_string(p["date"], "0:00") - 4 * 3600,
82
- :time_to => Time.create_time_from_string(p["date"], "0:00") + 8 * 3600,
83
- :temperature => p["tempMinC"].to_i
84
- }
85
- )
86
- weather_archives << hl
87
-
88
- # and high
89
- hh = h.clone.merge(
90
- {
91
- :wwo_type => :prediction_temp_high,
92
- :time_created => Time.now,
93
- :time_from => Time.create_time_from_string(p["date"], "0:00") + 8 * 3600,
94
- :time_to => Time.create_time_from_string(p["date"], "0:00") + 20 * 3600,
95
- :temperature => p["tempMaxC"].to_i
96
- }
97
- )
98
- weather_archives << hh
99
-
100
102
  end
101
103
 
102
104
  return WeatherData.factory(weather_archives)
@@ -12,7 +12,7 @@ module WeatherFetcher
12
12
  providers_to_remove = _wd.select{|w| w.next_fetch_time > Time.now}.collect{|w| w.provider}.uniq
13
13
 
14
14
  # remove providers
15
- recommended = all_providers_classes.select{|k| ([k.provider_name] & providers_to_remove).size == 0}
15
+ recommended = all_providers_classes.select{|k| puts k.provider_name.inspect; ([k.provider_name] & providers_to_remove).size == 0}
16
16
 
17
17
  return recommended
18
18
  end
metadata CHANGED
@@ -1,111 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weather_fetcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksander Kwiatkowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-24 00:00:00.000000000 Z
11
+ date: 2014-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curb
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: simple_metar_parser
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.0.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.0.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jeweler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rdoc
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: At this moment you can fetch weather http://www.worldweatheronline.com/,
@@ -130,6 +130,7 @@ 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/twoja_pogoda_pl.rb
133
134
  - lib/weather_fetcher/providers/html_based/world_weather_online.rb
134
135
  - lib/weather_fetcher/providers/html_based/wp_pl.rb
135
136
  - lib/weather_fetcher/providers/html_based_provider.rb
@@ -153,17 +154,17 @@ require_paths:
153
154
  - lib
154
155
  required_ruby_version: !ruby/object:Gem::Requirement
155
156
  requirements:
156
- - - '>='
157
+ - - ">="
157
158
  - !ruby/object:Gem::Version
158
159
  version: '0'
159
160
  required_rubygems_version: !ruby/object:Gem::Requirement
160
161
  requirements:
161
- - - '>='
162
+ - - ">="
162
163
  - !ruby/object:Gem::Version
163
164
  version: '0'
164
165
  requirements: []
165
166
  rubyforge_project:
166
- rubygems_version: 2.0.3
167
+ rubygems_version: 2.2.2
167
168
  signing_key:
168
169
  specification_version: 4
169
170
  summary: Fetch weather from various providers in one place