class WeatherFinder::Scrapper

Attributes

feels_like[RW]
hourly_array[RW]
temp[RW]
ten_day_arraay[RW]
uv[RW]

Public Class Methods

basic_scrapper(zip_code) click to toggle source
# File lib/weather_finder/weather-scrapper.rb, line 9
def self.basic_scrapper(zip_code)
  doc = Nokogiri::HTML(open("https://weather.com/weather/today/l/#{zip_code}:4:US"))
  @temp = doc.css(".today_nowcard-temp").text
  @uv = doc.css(".today_nowcard-hilo div").text
  @feel_like = doc.css(".deg-feels").text
  @uv.gsub!("UV Index ", "")
end
basic_weather(zip_code) click to toggle source
# File lib/weather_finder/weather-scrapper.rb, line 4
def self.basic_weather(zip_code)
  self.basic_scrapper(zip_code)
  [@temp,@uv,@feel_like]
end
hourly_weather(zip_code) click to toggle source
# File lib/weather_finder/weather-scrapper.rb, line 17
def self.hourly_weather(zip_code)
  @hourly_array = []

  doc = Nokogiri::HTML(open("https://weather.com/weather/today/l/#{zip_code}:4:US"))
  hourly_url = doc.css("ul li a")[1]['href']
  hourly_doc = Nokogiri::HTML(open("https://weather.com#{hourly_url}"))
  hourly_doc.css("tbody tr").each_with_index do |row, i|

    time = row.css(".dsx-date").text
    descrip = row.css(".description").text
    temp = row.css(".temp").text
    feels = row.css(".feels").text
    precip = row.css(".precip").text
    humidity = row.css(".humidity").text
    wind = row.css(".wind").text

    @hourly_array[i] = [time,descrip,temp,feels,precip,humidity,wind]

  end
  @hourly_array
end
ten_day_weather(zip_code) click to toggle source
# File lib/weather_finder/weather-scrapper.rb, line 39
def self.ten_day_weather(zip_code)
  @ten_day_array = []
  doc = Nokogiri::HTML(open("https://weather.com/weather/today/l/#{zip_code}:4:US"))
  ten_day_url = doc.css("ul li a")[2]['href']
  ten_day_doc = Nokogiri::HTML(open("https://weather.com#{ten_day_url}"))
  ten_day_doc.css("tbody tr").each_with_index do |row, i|

    time = row.css(".date-time").text
    descrip = row.css(".description").text
    high = row.css(".temp span")[0].text
    low = row.css(".temp span")[2].text
    precip = row.css(".precip").text
    humidity = row.css(".humidity").text
    wind = row.css(".wind").text

    @ten_day_array[i] = [time,descrip,high,low,precip,humidity,wind]
  end
  @ten_day_array
end