weather_fetcher 0.0.16 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -3
- data/Gemfile.lock +58 -22
- data/VERSION +1 -1
- data/lib/weather_fetcher/providers/html_based/interia_pl.rb +50 -108
- data/lib/weather_fetcher/providers/html_based/onet_pl.rb +26 -86
- data/lib/weather_fetcher/providers/html_based/world_weather_online.rb +2 -1
- data/lib/weather_fetcher/providers/html_based/wp_pl.rb +51 -83
- data/lib/weather_fetcher/providers/html_based_provider.rb +15 -1
- data/lib/weather_fetcher/providers/provider.rb +8 -0
- metadata +66 -39
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c4e125667ec4f19310d5d5fd67f808d78b0c8f22
|
4
|
+
data.tar.gz: 0f5834b7b8bbea71bc4ce3ac3e57b0fd2aa8110f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9800629a7cefc2f5f8ee4e0c808ae9aad1ad1b6b4fe1fff3d556443a12cef3dc9aa7db534189a2c7cc1970e249dfc3b7dbad160003c92492c7a13f6e1822d74f
|
7
|
+
data.tar.gz: bf7c4406acea6b09332b217d89bc1374b59cd0fb9177072db9eac8e7dabdf1a513101fa874e9e993ff7c86dfa2b9df4a4e941990195ea1aac941d50ba8c7e350
|
data/Gemfile
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
+
gem 'curb'
|
3
4
|
gem "simple_metar_parser", ">= 0.0.1"
|
4
5
|
|
5
6
|
group :development do
|
6
|
-
gem "rspec"
|
7
|
-
gem "bundler"
|
8
|
-
gem "jeweler"
|
7
|
+
gem "rspec"
|
8
|
+
gem "bundler"
|
9
|
+
gem "jeweler"
|
9
10
|
gem 'simplecov', :require => false, :group => :test
|
10
11
|
gem "rdoc"
|
11
12
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,38 +1,74 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
addressable (2.3.5)
|
5
|
+
builder (3.2.2)
|
6
|
+
curb (0.8.5)
|
7
|
+
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)
|
18
|
+
oauth2
|
19
|
+
hashie (2.0.5)
|
20
|
+
highline (1.6.20)
|
21
|
+
httpauth (0.2.0)
|
22
|
+
jeweler (1.8.8)
|
23
|
+
builder
|
7
24
|
bundler (~> 1.0)
|
8
25
|
git (>= 1.2.5)
|
26
|
+
github_api (= 0.10.1)
|
27
|
+
highline (>= 1.6.15)
|
28
|
+
nokogiri (= 1.5.10)
|
9
29
|
rake
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
30
|
+
rdoc
|
31
|
+
json (1.8.1)
|
32
|
+
jwt (0.1.8)
|
33
|
+
multi_json (>= 1.5)
|
34
|
+
multi_json (1.8.2)
|
35
|
+
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)
|
43
|
+
multi_xml (~> 0.5)
|
44
|
+
rack (~> 1.2)
|
45
|
+
rack (1.5.2)
|
46
|
+
rake (10.1.1)
|
47
|
+
rdoc (4.0.1)
|
14
48
|
json (~> 1.4)
|
15
|
-
rspec (2.
|
16
|
-
rspec-core (~> 2.
|
17
|
-
rspec-expectations (~> 2.
|
18
|
-
rspec-mocks (~> 2.
|
19
|
-
rspec-core (2.
|
20
|
-
rspec-expectations (2.
|
21
|
-
diff-lcs (
|
22
|
-
rspec-mocks (2.
|
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)
|
23
57
|
simple_metar_parser (0.0.1)
|
24
|
-
simplecov (0.
|
25
|
-
|
26
|
-
|
27
|
-
|
58
|
+
simplecov (0.8.2)
|
59
|
+
docile (~> 1.1.0)
|
60
|
+
multi_json
|
61
|
+
simplecov-html (~> 0.8.0)
|
62
|
+
simplecov-html (0.8.0)
|
28
63
|
|
29
64
|
PLATFORMS
|
30
65
|
ruby
|
31
66
|
|
32
67
|
DEPENDENCIES
|
33
|
-
bundler
|
34
|
-
|
68
|
+
bundler
|
69
|
+
curb
|
70
|
+
jeweler
|
35
71
|
rdoc
|
36
|
-
rspec
|
72
|
+
rspec
|
37
73
|
simple_metar_parser (>= 0.0.1)
|
38
74
|
simplecov
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -1,5 +1,7 @@
|
|
1
1
|
#encoding: utf-8
|
2
2
|
|
3
|
+
require 'nokogiri'
|
4
|
+
|
3
5
|
module WeatherFetcher
|
4
6
|
class Provider::InteriaPl < HtmlBasedProvider
|
5
7
|
|
@@ -8,122 +10,62 @@ module WeatherFetcher
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def process(string)
|
11
|
-
WeatherData.factory(
|
13
|
+
WeatherData.factory(_process(string))
|
12
14
|
end
|
13
15
|
|
14
16
|
# Process response body and rip out weather data
|
15
17
|
def _process(body_raw)
|
18
|
+
data = Array.new
|
19
|
+
b = Nokogiri::HTML(body_raw)
|
20
|
+
|
21
|
+
weather_days = b.css(".weather-forecast-day")
|
22
|
+
weather_days.each do |d|
|
23
|
+
klass = d.attribute("class").value
|
24
|
+
klass =~ /(\d{4})-(\d{1,2})-(\d{1,2})/
|
25
|
+
t = Time.local($1.to_i, $2.to_i, $3.to_i)
|
26
|
+
|
27
|
+
weather_list = d.css("li.weather-entry")
|
28
|
+
weather_list.each do |w|
|
29
|
+
hour = w.css(".entry-hour > .hour").children.first.to_s.to_i
|
30
|
+
min = w.css(".entry-hour > .minute").children.first.to_s.to_i
|
31
|
+
time_from = t + hour * 3600 + min * 60
|
32
|
+
|
33
|
+
temp = w.css(".forecast-top > .forecast-temp").children.first.to_s.to_f
|
34
|
+
feel_temp = w.css(".forecast-top > .forecast-feeltemp").children.first.to_s.gsub(/Odczuwalna/, "").to_f
|
35
|
+
wind = w.css(".wind-speed > .speed-value").children.first.to_s.to_f
|
36
|
+
rain = w.css("span.entry-precipitation-value.rain").children.first.to_s.gsub(/,/, ".").to_f
|
37
|
+
snow = w.css("span.entry-precipitation-value.snow").children.first
|
38
|
+
if snow
|
39
|
+
snow = snow.to_s.gsub(/,/, ".").to_f
|
40
|
+
else
|
41
|
+
snow = nil
|
42
|
+
end
|
43
|
+
cloud_cover = w.css("span.entry-precipitation-value.cloud-cover").children.first.to_s.to_f
|
44
|
+
humidity = w.css(".entry-humidity").children.first.to_s.to_f
|
45
|
+
# puts humidity.inspect
|
46
|
+
|
47
|
+
h = {
|
48
|
+
:time_created => Time.now,
|
49
|
+
:time_from => time_from,
|
50
|
+
:time_to => time_from + 3600,
|
51
|
+
:temperature => temp,
|
52
|
+
:feel_temperature => feel_temp,
|
53
|
+
# :pressure => pressures[0][0].to_f,
|
54
|
+
:wind_kmh => wind,
|
55
|
+
:wind => wind / 3.6,
|
56
|
+
# :snow => nil, #snows[0][0].to_f,
|
57
|
+
:rain => rain,
|
58
|
+
:cloud_cover => cloud_cover,
|
59
|
+
:humidity => humidity,
|
60
|
+
:provider => self.class.provider_name
|
61
|
+
}
|
62
|
+
|
63
|
+
data << h
|
64
|
+
end
|
16
65
|
|
17
|
-
body = body_raw.downcase
|
18
|
-
|
19
|
-
hours_first = body.scan(/(\d{2})\s*do\s*(\d{2})/)
|
20
|
-
#puts hours_first.inspect
|
21
|
-
hours_add = body.scan(/<td height=\"40\">.*(\d{2})-(\d{2}).*<\/td>/)
|
22
|
-
#puts hours_add.inspect
|
23
|
-
hours = hours_first + hours_add
|
24
|
-
#puts hours.inspect
|
25
|
-
|
26
|
-
# interia uses min/aesthes./max temperatures, aesth. used
|
27
|
-
temperatures = body.scan(/<span\s*class=\"tex2b\"\s*style=\"font-size:\s*14px;\">(-?\d+)<\/span>/)
|
28
|
-
# there is 'sample' temperature which should be deleted
|
29
|
-
temperatures.delete_at(2) # if temperatures[2] == 5
|
30
|
-
#puts temperatures.inspect
|
31
|
-
|
32
|
-
winds = body.scan(/wiatr:\D*(\d+)\D*km\/h\s*</)
|
33
|
-
#puts winds.inspect
|
34
|
-
|
35
|
-
rains = body.scan(/deszcz:\D*(\d+\.?\d*)\D*mm\s*</)
|
36
|
-
#puts rains.inspect
|
37
|
-
|
38
|
-
snows = body.scan(/nieg:\D*(\d+\.?\d*)\D*mm\s*</)
|
39
|
-
#puts snows.inspect
|
40
|
-
|
41
|
-
pressures = body.scan(/<b>(\d{3,4})<\/b>.*hpa/)
|
42
|
-
#puts pressures.inspect
|
43
|
-
|
44
|
-
# TODO fix it better!
|
45
|
-
#puts rains.inspect
|
46
|
-
#puts snows.inspect
|
47
|
-
if snows.nil? or snows.size < 2
|
48
|
-
snows = [[nil], [nil], [nil]]
|
49
|
-
end
|
50
|
-
if rains.nil? or rains.size < 2
|
51
|
-
rains = [[nil], [nil], [nil]]
|
52
|
-
end
|
53
|
-
|
54
|
-
unix_time_today = Time.mktime(
|
55
|
-
Time.now.year,
|
56
|
-
Time.now.month,
|
57
|
-
Time.now.day,
|
58
|
-
0, 0, 0, 0)
|
59
|
-
|
60
|
-
unix_time_now_from = unix_time_today + 3600 * hours[0][0].to_i
|
61
|
-
unix_time_now_to = unix_time_today + 3600 * hours[0][1].to_i
|
62
|
-
if hours[0][1].to_i < hours[0][0].to_i
|
63
|
-
# next day
|
64
|
-
unix_time_now_to += 24 * 3600
|
65
66
|
end
|
66
67
|
|
67
|
-
unix_time_soon_from = unix_time_today + 3600 * hours[1][0].to_i
|
68
|
-
unix_time_soon_to = unix_time_today + 3600 * hours[1][1].to_i
|
69
|
-
if hours[1][1].to_i < hours[1][0].to_i
|
70
|
-
# next day
|
71
|
-
unix_time_soon_to += 24 * 3600
|
72
|
-
end
|
73
|
-
if hours[1][0].to_i > hours[1][0].to_i
|
74
|
-
# time soon is whole new day
|
75
|
-
unix_time_soon_from += 24 * 3600
|
76
|
-
unix_time_soon_to += 24 * 3600
|
77
|
-
end
|
78
|
-
|
79
|
-
# if 1 data is for next day morning
|
80
|
-
if hours[0][1].to_i < Time.now.hour
|
81
|
-
unix_time_now_to += 24 * 3600
|
82
|
-
unix_time_now_from += 24 * 3600
|
83
|
-
|
84
|
-
unix_time_soon_to += 24 * 3600
|
85
|
-
unix_time_soon_from += 24 * 3600
|
86
|
-
end
|
87
|
-
|
88
|
-
# TODO zrób auto testy dla innych typów
|
89
|
-
# TODO i dodaj inkrementacje dnia po
|
90
|
-
# if 1 data is for next day morning
|
91
|
-
if unix_time_now_to > unix_time_soon_to
|
92
|
-
unix_time_soon_to += 24 * 3600
|
93
|
-
unix_time_soon_from += 24 * 3600
|
94
|
-
end
|
95
|
-
|
96
|
-
data = [
|
97
|
-
{
|
98
|
-
:time_created => Time.now,
|
99
|
-
:time_from => unix_time_now_from,
|
100
|
-
:time_to => unix_time_now_to,
|
101
|
-
:temperature => temperatures[0][0].to_f,
|
102
|
-
:pressure => pressures[0][0].to_f,
|
103
|
-
:wind_kmh => winds[0][0].to_f,
|
104
|
-
:wind => winds[0][0].to_f / 3.6,
|
105
|
-
:snow => snows[0][0].to_f,
|
106
|
-
:rain => rains[0][0].to_f,
|
107
|
-
:provider => self.class.provider_name
|
108
|
-
},
|
109
|
-
{
|
110
|
-
:time_created => Time.now,
|
111
|
-
:time_from => unix_time_soon_from,
|
112
|
-
:time_to => unix_time_soon_to,
|
113
|
-
:temperature => temperatures[1][0].to_f,
|
114
|
-
:pressure => pressures[1][0].to_f,
|
115
|
-
:wind_kmh => winds[1][0].to_f,
|
116
|
-
:wind => winds[1][0].to_f / 3.6,
|
117
|
-
:snow => snows[1][0].to_f,
|
118
|
-
:rain => rains[1][0].to_f,
|
119
|
-
:provider => self.class.provider_name
|
120
|
-
}
|
121
|
-
]
|
122
|
-
|
123
68
|
return data
|
124
69
|
end
|
125
|
-
|
126
70
|
end
|
127
|
-
|
128
71
|
end
|
129
|
-
|
@@ -1,5 +1,8 @@
|
|
1
1
|
#encoding: utf-8
|
2
2
|
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'time'
|
5
|
+
|
3
6
|
module WeatherFetcher
|
4
7
|
class Provider::OnetPl < HtmlBasedProvider
|
5
8
|
|
@@ -9,107 +12,44 @@ module WeatherFetcher
|
|
9
12
|
|
10
13
|
def process(string)
|
11
14
|
a = Array.new
|
12
|
-
a += WeatherData.factory(
|
15
|
+
a += WeatherData.factory(_process_body_long_term(string))
|
13
16
|
return a
|
14
17
|
end
|
15
18
|
|
16
19
|
# Process response body and rip out weather data, details
|
17
|
-
def
|
18
|
-
|
19
|
-
body_tmp = body_raw.downcase
|
20
|
-
body = body_tmp
|
21
|
-
|
22
|
-
times = body.scan(/<span class=\"time\">godz. <strong>(\d+)-(\d+)/i)
|
23
|
-
temperatures = body.scan(/<span class="temp">\s*(-*\d+)[^<]+<\/span>/i)
|
24
|
-
pressures = body.scan(/(\d*)\s*hpa/i)
|
25
|
-
winds = body.scan(/(\d*)\s*km\/h/)
|
26
|
-
# no more snow :(
|
27
|
-
#snows = body.scan(/nieg:<\/td><td class=\"[^"]*\">\s*([0-9.]*)\s*mm</)
|
28
|
-
snow = []
|
29
|
-
#rains = body.scan(/Deszcz:\s*<\/label>\s*([0-9,]+)\s*mm/i)
|
30
|
-
rains = body.scan(/Deszcz:[^0-9]*([0-9,]+)\s*mm/i)
|
31
|
-
|
32
|
-
unix_time_today = Time.mktime(
|
33
|
-
Time.now.year,
|
34
|
-
Time.now.month,
|
35
|
-
Time.now.day,
|
36
|
-
0, 0, 0, 0)
|
37
|
-
|
38
|
-
# should be ok
|
39
|
-
# puts times.size, temperatures.size, pressures.size, winds.size, rains.size
|
40
|
-
# puts times.inspect, temperatures.inspect, pressures.inspect, winds.inspect, rains.inspect
|
41
|
-
|
20
|
+
def _process_body_long_term(body_raw)
|
42
21
|
data = Array.new
|
22
|
+
b = Nokogiri::HTML(body_raw)
|
43
23
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
:time_from => unix_time_today + times[i][0].to_i * 3600,
|
49
|
-
:time_to => unix_time_today + times[i][1].to_i * 3600,
|
50
|
-
:temperature => temperatures[1 + i][0].to_f,
|
51
|
-
:pressure => pressures[0][0].to_f,
|
52
|
-
:wind_kmh => winds[0][0].to_f,
|
53
|
-
:wind => winds[0][0].to_f / 3.6,
|
54
|
-
:snow => nil, #snows[0][0].to_f,
|
55
|
-
:rain => rains[0][0].gsub(/,/, '.').to_f,
|
56
|
-
:provider => self.class.provider_name
|
57
|
-
}
|
58
|
-
h[:time_to] += 24*3600 if h[:time_to] < h[:time_from]
|
24
|
+
weather_days = b.css(".day-longterm")
|
25
|
+
weather_days.each do |weather_day|
|
26
|
+
time_from = Time.parse(weather_day.css("time").attribute("datetime").value.to_s)
|
27
|
+
temp = weather_day.css(".temp").children.first.to_s.to_f
|
59
28
|
|
60
|
-
|
61
|
-
|
29
|
+
desc = weather_day.css(".details").children.collect { |d| d.to_s.gsub(/\n/, "").gsub(/\t/, "") }
|
30
|
+
pressure = desc[3].to_f
|
31
|
+
wind = desc[7].to_f
|
32
|
+
rain = desc[10].gsub(/,/, '.').to_f
|
62
33
|
|
63
|
-
# tomorrow
|
64
|
-
(4..7).each do |i|
|
65
34
|
h = {
|
66
35
|
:time_created => Time.now,
|
67
|
-
:time_from =>
|
68
|
-
:time_to =>
|
69
|
-
:temperature =>
|
70
|
-
|
71
|
-
:
|
72
|
-
:
|
73
|
-
:
|
74
|
-
:
|
36
|
+
:time_from => time_from,
|
37
|
+
:time_to => time_from + 24*3600,
|
38
|
+
:temperature => temp,
|
39
|
+
#:feel_temperature => feel_temp,
|
40
|
+
:pressure => pressure,
|
41
|
+
:wind_kmh => wind,
|
42
|
+
:wind => wind / 3.6,
|
43
|
+
# :snow => nil, #snows[0][0].to_f,
|
44
|
+
:rain => rain,
|
45
|
+
#:cloud_cover => cloud_cover,
|
46
|
+
#:humidity => humidity,
|
75
47
|
:provider => self.class.provider_name
|
76
48
|
}
|
77
|
-
h[:time_to] += 24*3600 if h[:time_to] < h[:time_from]
|
78
|
-
|
79
49
|
data << h
|
80
|
-
end
|
81
|
-
# puts data.to_yaml
|
82
|
-
|
83
|
-
# longer
|
84
|
-
dates = body.scan(/<time datetime=\"(\d{4})-(\d{1,2})-(\d{1,2})\">/i)
|
85
50
|
|
86
|
-
|
87
|
-
(0..9).each do |i|
|
88
|
-
unix_time = Time.mktime(
|
89
|
-
dates[i][0].to_i,
|
90
|
-
dates[i][1].to_i,
|
91
|
-
dates[i][2].to_i
|
92
|
-
)
|
93
|
-
# puts unix_time, dates[i].inspect
|
94
|
-
|
95
|
-
h = {
|
96
|
-
:time_created => Time.now,
|
97
|
-
:time_from => unix_time,
|
98
|
-
:time_to => unix_time + 24*3600,
|
99
|
-
:temperature => temperatures[13 + i][0].to_f,
|
100
|
-
:pressure => pressures[3 + i][0].to_f,
|
101
|
-
:wind_kmh => winds[3 + i][0].to_f,
|
102
|
-
:wind => winds[3 + i][0].to_f / 3.6,
|
103
|
-
:snow => nil, #snows[0][0].to_f,
|
104
|
-
:rain => rains[3 + i][0].gsub(/,/, '.').to_f,
|
105
|
-
:provider => self.class.provider_name
|
106
|
-
}
|
107
|
-
h[:time_to] += 24*3600 if h[:time_to] < h[:time_from]
|
108
|
-
|
109
|
-
data << h
|
51
|
+
# puts h.inspect
|
110
52
|
end
|
111
|
-
# puts data.to_yaml
|
112
|
-
|
113
53
|
return data
|
114
54
|
end
|
115
55
|
|
@@ -25,7 +25,8 @@ 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"
|
28
|
+
#"http://free.worldweatheronline.com/feed/weather.ashx?key=#{@@api}&q=#{p[:coords][:lat]},#{p[:coords][:lon]}&num_of_days=2&format=json"
|
29
|
+
"http://api.worldweatheronline.com/free/v1/weather.ashx?q=#{p[:coords][:lat]},#{p[:coords][:lon]}&format=json&num_of_days=5&key=#{@@api}"
|
29
30
|
end
|
30
31
|
|
31
32
|
def can_fetch?(p)
|
@@ -1,5 +1,8 @@
|
|
1
1
|
#encoding: utf-8
|
2
2
|
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'time'
|
5
|
+
|
3
6
|
module WeatherFetcher
|
4
7
|
class Provider::WpPl < HtmlBasedProvider
|
5
8
|
|
@@ -8,105 +11,70 @@ module WeatherFetcher
|
|
8
11
|
end
|
9
12
|
|
10
13
|
def process(string)
|
11
|
-
return WeatherData.factory(
|
14
|
+
return WeatherData.factory(_process(string))
|
12
15
|
end
|
13
16
|
|
14
17
|
# Process response body and rip out weather data
|
15
18
|
def _process(body_raw)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
if ih > 0 and hours[ih][0].to_i < hours[ih - 1][0].to_i
|
36
|
-
i_day += 1
|
19
|
+
data = Array.new
|
20
|
+
b = Nokogiri::HTML(body_raw)
|
21
|
+
|
22
|
+
current_day_time = unix_time_today
|
23
|
+
weather_days = b.css(".obszar")
|
24
|
+
weather_days.each do |w|
|
25
|
+
time = w.css(".czas").children.first.to_s.gsub(/\s/, '')
|
26
|
+
time =~ /(\d{2}):(\d{2})-(\d{2}):(\d{2})/
|
27
|
+
time_from = current_day_time + 3600*$1.to_i + 60*$2.to_i
|
28
|
+
time_to = current_day_time + 3600*$3.to_i + 60*$4.to_i
|
29
|
+
|
30
|
+
temp_night = w.css(".tempNoc").children.first
|
31
|
+
temp_day = w.css(".tempDzien").children.first
|
32
|
+
temp = nil
|
33
|
+
if temp_night
|
34
|
+
temp = temp_night.children.first.to_s.to_f
|
35
|
+
end
|
36
|
+
if temp_day
|
37
|
+
temp = temp_day.children.first.to_s.to_f
|
37
38
|
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
days[i_day][2].to_i,
|
44
|
-
days[i_day][1].to_i,
|
45
|
-
days[i_day][0].to_i,
|
46
|
-
hour_from,
|
47
|
-
0,
|
48
|
-
0,
|
49
|
-
0
|
50
|
-
)
|
51
|
-
time_from += 24*3600 if hours[ih][0].to_i == 24
|
52
|
-
|
53
|
-
hour_to = hours[ih][1].to_i
|
54
|
-
hour_to = 0 if hour_to == 24
|
55
|
-
time_to = Time.mktime(
|
56
|
-
days[i_day][2].to_i,
|
57
|
-
days[i_day][1].to_i,
|
58
|
-
days[i_day][0].to_i,
|
59
|
-
hour_to,
|
60
|
-
0,
|
61
|
-
0,
|
62
|
-
0
|
63
|
-
)
|
64
|
-
time_to += 24*3600 if hours[ih][1].to_i == 24
|
65
|
-
|
66
|
-
h = { :time_from => time_from, :time_to => time_to }
|
67
|
-
times << h
|
68
|
-
end
|
69
|
-
# puts times.to_yaml
|
70
|
-
#puts times.size
|
71
|
-
|
72
|
-
temperatures = body.scan(/temperatura:\s*<strong>(-?\d+)[^<]*<\/strong>/)
|
73
|
-
#puts temperatures.inspect
|
74
|
-
#puts temperatures.size
|
40
|
+
temp_feel = w.css(".tempOdczuwalna").children.first
|
41
|
+
if temp_feel
|
42
|
+
temp_feel = temp_feel.children.first.to_s.to_f
|
43
|
+
end
|
75
44
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
#puts winds.size
|
45
|
+
pressure = w.css("span.cisnienie").children.first
|
46
|
+
if pressure
|
47
|
+
pressure = pressure.to_s.to_f
|
48
|
+
end
|
81
49
|
|
82
|
-
|
50
|
+
rain = w.css(".opady").children.first
|
51
|
+
if rain
|
52
|
+
rain = rain.children[1].to_s.to_f
|
53
|
+
end
|
83
54
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
wind_speed_km_per_h = winds[i][0]
|
89
|
-
if t.nil?
|
90
|
-
wind_speed_km_per_h = nil
|
91
|
-
w = nil
|
92
|
-
else
|
93
|
-
wind_speed_km_per_h = wind_speed_km_per_h.to_f
|
94
|
-
w = wind_speed_km_per_h / 3.6
|
55
|
+
wind = w.css(".wiatrPredkosc").children.first
|
56
|
+
if wind
|
57
|
+
wind = wind.children.first.to_s.to_f
|
95
58
|
end
|
96
59
|
|
97
60
|
h = {
|
98
61
|
:time_created => Time.now,
|
99
|
-
:time_from =>
|
100
|
-
:time_to =>
|
101
|
-
:temperature =>
|
102
|
-
|
103
|
-
:
|
104
|
-
:
|
105
|
-
|
106
|
-
|
62
|
+
:time_from => time_from,
|
63
|
+
:time_to => time_to,
|
64
|
+
:temperature => temp,
|
65
|
+
:feel_temperature => temp_feel,
|
66
|
+
:pressure => pressure,
|
67
|
+
:wind_kmh => wind,
|
68
|
+
:wind => wind / 3.6,
|
69
|
+
# :snow => nil, #snows[0][0].to_f,
|
70
|
+
:rain => rain,
|
71
|
+
#:cloud_cover => cloud_cover,
|
72
|
+
#:humidity => humidity,
|
107
73
|
:provider => self.class.provider_name
|
108
74
|
}
|
109
75
|
|
76
|
+
# puts h.inspect
|
77
|
+
|
110
78
|
data << h
|
111
79
|
end
|
112
80
|
|
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'net/http'
|
2
|
+
require 'curb'
|
2
3
|
|
3
4
|
# All ugly providers who parse even uglier html code and rip off data
|
4
5
|
module WeatherFetcher
|
5
6
|
class HtmlBasedProvider < Provider
|
6
7
|
|
7
8
|
TYPE = :html_based
|
9
|
+
USER_AGENT = "Chrome 32.0.1667.0"
|
8
10
|
|
9
11
|
# Get processed weather for one definition
|
10
12
|
def fetch_and_process_single(p)
|
@@ -22,8 +24,20 @@ module WeatherFetcher
|
|
22
24
|
end
|
23
25
|
|
24
26
|
# Download url
|
27
|
+
def fetch_url_old(url)
|
28
|
+
s = Net::HTTP.get2(URI.parse(url), { 'User-Agent' => USERAGENT })
|
29
|
+
puts s.inspect, url
|
30
|
+
return s
|
31
|
+
end
|
32
|
+
|
25
33
|
def fetch_url(url)
|
26
|
-
|
34
|
+
http = Curl::Easy.perform(url) do |curl|
|
35
|
+
curl.headers["User-Agent"] = USER_AGENT
|
36
|
+
curl.enable_cookies = true
|
37
|
+
curl.follow_location = true
|
38
|
+
end
|
39
|
+
s = http.body_str
|
40
|
+
return s
|
27
41
|
end
|
28
42
|
|
29
43
|
# Url for current provider
|
@@ -88,6 +88,14 @@ module WeatherFetcher
|
|
88
88
|
raise NotImplementedError
|
89
89
|
end
|
90
90
|
|
91
|
+
def unix_time_today
|
92
|
+
Time.mktime(
|
93
|
+
Time.now.year,
|
94
|
+
Time.now.month,
|
95
|
+
Time.now.day,
|
96
|
+
0, 0, 0, 0)
|
97
|
+
end
|
98
|
+
|
91
99
|
def self.short_class_name
|
92
100
|
self.to_s.gsub(/^.*::/, '')
|
93
101
|
end
|
metadata
CHANGED
@@ -1,82 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weather_fetcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Aleksander Kwiatkowski
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-12-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: curb
|
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'
|
14
27
|
- !ruby/object:Gem::Dependency
|
15
28
|
name: simple_metar_parser
|
16
|
-
requirement:
|
17
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
18
30
|
requirements:
|
19
|
-
- -
|
31
|
+
- - '>='
|
20
32
|
- !ruby/object:Gem::Version
|
21
33
|
version: 0.0.1
|
22
34
|
type: :runtime
|
23
35
|
prerelease: false
|
24
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.1
|
25
41
|
- !ruby/object:Gem::Dependency
|
26
42
|
name: rspec
|
27
|
-
requirement:
|
28
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
29
44
|
requirements:
|
30
|
-
- -
|
45
|
+
- - '>='
|
31
46
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
47
|
+
version: '0'
|
33
48
|
type: :development
|
34
49
|
prerelease: false
|
35
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
36
55
|
- !ruby/object:Gem::Dependency
|
37
56
|
name: bundler
|
38
|
-
requirement:
|
39
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
40
58
|
requirements:
|
41
|
-
- -
|
59
|
+
- - '>='
|
42
60
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
61
|
+
version: '0'
|
44
62
|
type: :development
|
45
63
|
prerelease: false
|
46
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
47
69
|
- !ruby/object:Gem::Dependency
|
48
70
|
name: jeweler
|
49
|
-
requirement:
|
50
|
-
none: false
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
51
72
|
requirements:
|
52
|
-
- -
|
73
|
+
- - '>='
|
53
74
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
75
|
+
version: '0'
|
55
76
|
type: :development
|
56
77
|
prerelease: false
|
57
|
-
version_requirements:
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
58
83
|
- !ruby/object:Gem::Dependency
|
59
84
|
name: simplecov
|
60
|
-
requirement:
|
61
|
-
none: false
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
62
86
|
requirements:
|
63
|
-
- -
|
87
|
+
- - '>='
|
64
88
|
- !ruby/object:Gem::Version
|
65
89
|
version: '0'
|
66
90
|
type: :development
|
67
91
|
prerelease: false
|
68
|
-
version_requirements:
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: rdoc
|
71
|
-
requirement:
|
72
|
-
none: false
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
73
100
|
requirements:
|
74
|
-
- -
|
101
|
+
- - '>='
|
75
102
|
- !ruby/object:Gem::Version
|
76
103
|
version: '0'
|
77
104
|
type: :development
|
78
105
|
prerelease: false
|
79
|
-
version_requirements:
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
80
111
|
description: At this moment you can fetch weather http://www.worldweatheronline.com/,
|
81
112
|
from various Polish websites (Onet.pl, Wp.pl, Interia.pl) and from some METAR providers.
|
82
113
|
More providers coming soon :)
|
@@ -115,29 +146,25 @@ files:
|
|
115
146
|
homepage: http://github.com/akwiatkowski/weather_fetcher
|
116
147
|
licenses:
|
117
148
|
- LGPLv3
|
149
|
+
metadata: {}
|
118
150
|
post_install_message:
|
119
151
|
rdoc_options: []
|
120
152
|
require_paths:
|
121
153
|
- lib
|
122
154
|
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
-
none: false
|
124
155
|
requirements:
|
125
|
-
- -
|
156
|
+
- - '>='
|
126
157
|
- !ruby/object:Gem::Version
|
127
158
|
version: '0'
|
128
|
-
segments:
|
129
|
-
- 0
|
130
|
-
hash: -4097979390535855784
|
131
159
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
-
none: false
|
133
160
|
requirements:
|
134
|
-
- -
|
161
|
+
- - '>='
|
135
162
|
- !ruby/object:Gem::Version
|
136
163
|
version: '0'
|
137
164
|
requirements: []
|
138
165
|
rubyforge_project:
|
139
|
-
rubygems_version:
|
166
|
+
rubygems_version: 2.0.3
|
140
167
|
signing_key:
|
141
|
-
specification_version:
|
168
|
+
specification_version: 4
|
142
169
|
summary: Fetch weather from various providers in one place
|
143
170
|
test_files: []
|