Sha256: c715073e39d4b2770ab792c1fa6c7d28d2b9eeaa2fea8e918be84ddec574a3fd
Contents?: true
Size: 1.37 KB
Versions: 2
Compression:
Stored size: 1.37 KB
Contents
class MasonellwoodCliAppTwo::StateScraper attr_accessor :name, :cities, :state, :url def initialize(state) @state = state end def scrape_cities html = open("https://www.wunderground.com/cgi-bin/findweather/getForecast?query=#{@state}") #pulls html student_file = Nokogiri::HTML(html) cities_array = [] student_file.css("tbody tr").each do |x| city = x.css("a").text url = x.search("a").attr("href").value cities_array << "#{city} : #{url}" end @cities = cities_array end def city_weather(input) input_city = input self.cities.each do |x| citys = x.split(/ : /) downcase_city = citys[0].downcase if downcase_city == input_city html = open("https://www.wunderground.com/#{citys[1]}") #pulls html student_file = Nokogiri::HTML(html) weather_conditions = student_file.css("#curCond .wx-value").text temperature = student_file.css("#curTemp .wx-value").text puts "It looks like you are interested in beautiful #{input_city.capitalize}!" puts "Weather Conditions for Today: #{weather_conditions}" puts "Current Temperature: #{temperature} Degrees Fahrenheit" puts "Check more or the Cities in your area by typing the City name." puts "If you want to see all the Cities again, type Cities." puts "Or type exit." end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
masonellwood_cli_app_two-0.1.1 | lib/masonellwood_cli_app_two/state-scraper.rb |
masonellwood_cli_app_two-0.1.0 | lib/masonellwood_cli_app_two/state-scraper.rb |