Class: WeatherFetcher::Provider::InteriaPl
- Inherits:
-
HtmlBasedProvider
- Object
- WeatherFetcher::Provider
- HtmlBasedProvider
- WeatherFetcher::Provider::InteriaPl
- Defined in:
- lib/weather_fetcher/providers/html_based/interia_pl.rb
Constant Summary
Constants inherited from HtmlBasedProvider
HtmlBasedProvider::TYPE, HtmlBasedProvider::USER_AGENT
Constants inherited from WeatherFetcher::Provider
Instance Attribute Summary
Attributes inherited from WeatherFetcher::Provider
Class Method Summary collapse
Instance Method Summary collapse
-
#_process(body_raw) ⇒ Object
Process response body and rip out weather data.
- #process(string) ⇒ Object
Methods inherited from HtmlBasedProvider
#can_fetch?, #fetch_and_process_single, #fetch_url, #fetch_url_old, #url, weather_updated_every
Methods inherited from WeatherFetcher::Provider
#can_fetch?, #fetch, #fetch_and_process_single, #initialize, #provider_name, #provider_params, #short_class_name, short_class_name, #store_city_definition, #store_time_costs, #unix_time_today, #url
Constructor Details
This class inherits a constructor from WeatherFetcher::Provider
Class Method Details
.provider_name ⇒ Object
8 9 10 |
# File 'lib/weather_fetcher/providers/html_based/interia_pl.rb', line 8 def self.provider_name "Interia.pl" end |
Instance Method Details
#_process(body_raw) ⇒ Object
Process response body and rip out weather data
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/weather_fetcher/providers/html_based/interia_pl.rb', line 17 def _process(body_raw) data = Array.new b = Nokogiri::HTML(body_raw) weather_days = b.css(".weather-forecast-day") weather_days.each do |d| klass = d.attribute("class").value klass =~ /(\d{4})-(\d{1,2})-(\d{1,2})/ t = Time.local($1.to_i, $2.to_i, $3.to_i) weather_list = d.css("li.weather-entry") weather_list.each do |w| hour = w.css(".entry-hour > .hour").children.first.to_s.to_i min = w.css(".entry-hour > .minute").children.first.to_s.to_i time_from = t + hour * 3600 + min * 60 temp = w.css(".forecast-top > .forecast-temp").children.first.to_s.to_f feel_temp = w.css(".forecast-top > .forecast-feeltemp").children.first.to_s.gsub(/Odczuwalna/, "").to_f wind = w.css(".wind-speed > .speed-value").children.first.to_s.to_f rain = w.css("span.entry-precipitation-value.rain").children.first.to_s.gsub(/,/, ".").to_f snow = w.css("span.entry-precipitation-value.snow").children.first if snow snow = snow.to_s.gsub(/,/, ".").to_f else snow = nil end cloud_cover = w.css("span.entry-precipitation-value.cloud-cover").children.first.to_s.to_f humidity = w.css(".entry-humidity").children.first.to_s.to_f # puts humidity.inspect h = { :time_created => Time.now, :time_from => time_from, :time_to => time_from + 3600, :temperature => temp, :feel_temperature => feel_temp, # :pressure => pressures[0][0].to_f, :wind_kmh => wind, :wind => wind / 3.6, # :snow => nil, #snows[0][0].to_f, :rain => rain, :cloud_cover => cloud_cover, :humidity => humidity, :provider => self.class.provider_name } data << h end end return data end |
#process(string) ⇒ Object
12 13 14 |
# File 'lib/weather_fetcher/providers/html_based/interia_pl.rb', line 12 def process(string) WeatherData.factory(_process(string)) end |