<commit_before>require 'net/http'
require 'json'

class Wunderground
  include Cinch::Plugin

  match /wu (.+)$/

  def execute(m, location)
    m.reply weather(location), true
  end

  private

  def weather(location)

    # Wunderground doesn't seem to have a search within the conditions API so we have to get it first...
    uri = URI.parse("http://autocomplete.wunderground.com/aq?query=#{URI.encode(location)}")
    Net::HTTP.start(uri.host, uri.port) do |h|

      resp = Net::HTTP.get_response(uri)
      @loc = JSON.parse(resp.body)
      #@latlong = loc['RESULTS'][0]['ll']

    end

    if !@loc['RESULTS'][0].nil?

      @latlong = @loc['RESULTS'][0]['ll']

      # http://api.wunderground.com/api/APIKEY/features/settings/q/query.format
      uri = URI.parse("http://api.wunderground.com/api/#{WUWEATHERAPIKEY}/conditions/q/#{@latlong.gsub(" ",",")}.json")
      Net::HTTP.start(uri.host, uri.port) do |http|

        resp        = Net::HTTP.get_response(uri)
        data        = JSON.parse(resp.body)

        if data.include?('current_observation')

          weather     = data['current_observation']
          location    = weather['display_location']['full']
          time        = weather['observation_time'].partition(", ").last
          wxdesc      = weather['weather']
          temp        = weather['temperature_string']
          humidity    = weather['relative_humidity']
          winddir     = weather['wind_dir']
          windmph     = weather['wind_mph']
          windkph     = weather['wind_kph']
          visimi      = weather['visibility_mi']
          visikm      = weather['visibility_km']
          pressurein  = weather['pressure_in']
          pressuremb  = weather['pressure_mb']
          link        = weather['ob_url']

          return Format(:bold,"Current Weather") + " in #{location} (As of #{time}) - " + Format(:underline,"#{wxdesc}") + ", #{temp}, " + Format(:bold,"Humidity:") + " #{humidity}, " + Format(:bold,"Wind:") + " #{winddir} #{windmph}mph (#{windkph}kph), " + Format(:bold,"Visbility:") + " #{visimi}mi (#{visikm}km), " + Format(:bold,"Pressure:") +" #{pressurein}inHg (#{pressuremb}mbar). #{link}"

        elsif data.include?('response')

          error       = data['response']['error']<commit_msg>Wunderground Plugin - Bold not underline...<commit_after>require 'net/http'
require 'json'

class Wunderground
  include Cinch::Plugin

  match /wu (.+)$/

  def execute(m, location)
    m.reply weather(location), true
  end

  private

  def weather(location)

    # Wunderground doesn't seem to have a search within the conditions API so we have to get it first...
    uri = URI.parse("http://autocomplete.wunderground.com/aq?query=#{URI.encode(location)}")
    Net::HTTP.start(uri.host, uri.port) do |h|

      resp = Net::HTTP.get_response(uri)
      @loc = JSON.parse(resp.body)
      #@latlong = loc['RESULTS'][0]['ll']

    end

    if !@loc['RESULTS'][0].nil?

      @latlong = @loc['RESULTS'][0]['ll']

      # http://api.wunderground.com/api/APIKEY/features/settings/q/query.format
      uri = URI.parse("http://api.wunderground.com/api/#{WUWEATHERAPIKEY}/conditions/q/#{@latlong.gsub(" ",",")}.json")
      Net::HTTP.start(uri.host, uri.port) do |http|

        resp        = Net::HTTP.get_response(uri)
        data        = JSON.parse(resp.body)

        if data.include?('current_observation')

          weather     = data['current_observation']
          location    = weather['display_location']['full']
          time        = weather['observation_time'].partition(", ").last
          wxdesc      = weather['weather']
          temp        = weather['temperature_string']
          humidity    = weather['relative_humidity']
          winddir     = weather['wind_dir']
          windmph     = weather['wind_mph']
          windkph     = weather['wind_kph']
          visimi      = weather['visibility_mi']
          visikm      = weather['visibility_km']
          pressurein  = weather['pressure_in']
          pressuremb  = weather['pressure_mb']
          link        = weather['ob_url']

          return Format(:bold,"Current Weather") + " in #{location} (As of #{time}) - " + Format(:bold,"#{wxdesc}") + ", #{temp}, " + Format(:bold,"Humidity:") + " #{humidity}, " + Format(:bold,"Wind:") + " #{winddir} #{windmph}mph (#{windkph}kph), " + Format(:bold,"Visbility:") + " #{visimi}mi (#{visikm}km), " + Format(:bold,"Pressure:") +" #{pressurein}inHg (#{pressuremb}mbar). #{link}"

        elsif data.include?('response')

          error       = data['response']['error']
{'fraction_non_alphanumeric': 0.1740083278544817, 'fraction_numerical': 0.0013149243918474688, 'mean_word_length': 2.7970049916805326, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '777092', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1395, 'n_words': 253}