<commit_before>require 'nokogiri'
require 'open-uri'

class Thundersnow
  class << self
    def run(location)
      @xml = Nokogiri::XML(open("http://www.google.com/ig/api?weather=#{location}"))

      show :city
      puts "-------------------------"
      show :condition
      show :temperatures
      show :wind
      show :humidity
      puts "-------------------------"
      show :forecast
    end

  private

    def show(name)
      puts send(name)
    end

    def city
      city = read_attr(@xml, '//forecast_information/city')
      "Weather forecast for #{city}"
    end

    def condition
      read_attr(current_conditions, 'condition')
    end

    def temperatures
      "#{temp_f} / #{temp_c}"
    end
<commit_msg>bettter error handling for invalid locations<commit_after>require 'nokogiri'
require 'open-uri'

class Thundersnow
  class << self
    def run(location)
      uri = URI.encode "http://www.google.com/ig/api?weather=#{location}"
      @xml = Nokogiri::XML(open(uri))

      if @xml.xpath('//weather/problem_cause')
        return puts "Could not locate weather for #{location}"
      end

      show :city
      puts "-------------------------"
      show :condition
      show :temperatures
      show :wind
      show :humidity
      puts "-------------------------"
      show :forecast
    end

  private

    def show(name)
      puts send(name)
    end

    def city
      city = read_attr(@xml, '//forecast_information/city')
      "Weather forecast for #{city}"
    end

    def condition
      read_attr(current_conditions, 'condition')
    end

    def temperatures
      "#{temp_f} / #{temp_c}"
    end

{'fraction_non_alphanumeric': 0.1641337386018237, 'fraction_numerical': 0.0, 'mean_word_length': 1.9236234458259325, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 5}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4074916', 'n_tokens_mistral': 503, 'n_tokens_neox': 490, 'n_words': 125}