<commit_before>class WeatherMan
  @w_api = Wunderground.new(ENV["WUNDERGROUND_API_KEY"])

  def self.current_outdoor_temp(zip_code)
    key = "current_outdoor_temp_for_#{zip_code}"
    Rails.cache.fetch(key, :expires_in => 15.minutes) do
      json_object = @w_api.conditions_for(zip_code)
      json_object["current_observation"]["temp_f"]
    end
  end

  def self.outdoor_temp_for(time, zip_code)
    key = "outdoor_temp_for_#{zip_code}_at_#{time.strftime '%Y-%m-%dT%I'}"
    Rails.cache.fetch(key, :expires_in => 1.day) do
      observations = @w_api.history_for(time, zip_code)['history']['observations']
      observations.each do |o|
        if o['date']['hour'] == time.hour.to_s
          return o['tempi'].to_i
        end
      end
    end
  end
end<commit_msg>Throttle API calls to WUnderground<commit_after>class WeatherMan
  @w_api = Wunderground.new(ENV["WUNDERGROUND_API_KEY"])

  def self.current_outdoor_temp(zip_code)
    key = "current_outdoor_temp_for_#{zip_code}"
    Rails.cache.fetch(key, :expires_in => 15.minutes) do
      json_object = @w_api.conditions_for(zip_code)
      json_object["current_observation"]["temp_f"]
    end
  end

  def self.outdoor_temp_for(time, zip_code)
    key = "outdoor_temp_for_#{zip_code}_at_#{time.strftime '%Y-%m-%dT%I'}"
    Rails.cache.fetch(key, :expires_in => 1.day) do
      sleep 1
      observations = @w_api.history_for(time, zip_code)['history']['observations']
      observations.each do |o|
        if o['date']['hour'] == time.hour.to_s
          return o['tempi'].to_i
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.13679544015199493, 'fraction_numerical': 0.004433185560481318, 'mean_word_length': 3.744744744744745, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6509959', 'n_tokens_mistral': 598, 'n_tokens_neox': 593, 'n_words': 91}