Class: WeatherFetcher::Provider::WpPl

Inherits:
HtmlBasedProvider show all
Defined in:
lib/weather_fetcher/providers/html_based/wp_pl.rb

Constant Summary

Constants inherited from HtmlBasedProvider

HtmlBasedProvider::TYPE, HtmlBasedProvider::USER_AGENT

Constants inherited from WeatherFetcher::Provider

HOUR, TYPE

Instance Attribute Summary

Attributes inherited from WeatherFetcher::Provider

#defs, #logger, #weathers

Class Method Summary collapse

Instance Method Summary collapse

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_nameObject



9
10
11
# File 'lib/weather_fetcher/providers/html_based/wp_pl.rb', line 9

def self.provider_name
  "Wp.pl"
end

Instance Method Details

#_process(body_raw) ⇒ Object

Process response body and rip out weather data



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
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/weather_fetcher/providers/html_based/wp_pl.rb', line 18

def _process(body_raw)
  data = Array.new
  b = Nokogiri::HTML(body_raw)

  current_day_time = unix_time_today
  weather_days = b.css(".obszar")
  weather_days.each do |w|
    time = w.css(".czas").children.first.to_s.gsub(/\s/, '')
    time =~ /(\d{2}):(\d{2})-(\d{2}):(\d{2})/
    time_from = current_day_time + 3600*$1.to_i + 60*$2.to_i
    time_to = current_day_time + 3600*$3.to_i + 60*$4.to_i

    temp_night = w.css(".tempNoc").children.first
    temp_day = w.css(".tempDzien").children.first
    temp = nil
    if temp_night
      temp = temp_night.children.first.to_s.to_f
    end
    if temp_day
      temp = temp_day.children.first.to_s.to_f
    end

    temp_feel = w.css(".tempOdczuwalna").children.first
    if temp_feel
      temp_feel = temp_feel.children.first.to_s.to_f
    end

    pressure = w.css("span.cisnienie").children.first
    if pressure
      pressure = pressure.to_s.to_f
    end

    rain = w.css(".opady").children.first
    if rain
      rain = rain.children[1].to_s.to_f
    end

    wind = w.css(".wiatrPredkosc").children.first
    if wind
      wind = wind.children.first.to_s.to_f
    end

    h = {
      :time_created => Time.now,
      :time_from => time_from,
      :time_to => time_to,
      :temperature => temp,
      :feel_temperature => temp_feel,
      :pressure => pressure,
      :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
    }

    # puts h.inspect

    data << h
  end

  return data
end

#process(string) ⇒ Object



13
14
15
# File 'lib/weather_fetcher/providers/html_based/wp_pl.rb', line 13

def process(string)
  return WeatherData.factory(_process(string))
end