Sha256: aa115d35d97b331dd23449d77a24a646f328b44f1c477e265f116f1a466d1026

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

# -*- coding: utf-8 -*-
require 'cinch'
require 'cinch-cooldown'
require 'time-lord'
require 'weather-underground'

module Cinch::Plugins
  class Weatherman
    include Cinch::Plugin

    enforce_cooldown

    self.help = "Use .w <location> to see information on the weather. (e.g. .w 94062)"

    match /w (.*)/
    match /weather (.*)/

    def execute(m, query)
      m.reply get_weather(query)
    end

    private

    def get_weather(query)
      location, temp_f, conditions, updated = get_forcast(query)

      message = "In #{location} it is #{conditions} "
      message << "and #{temp_f}°F "
      message << "(last updated about #{updated})"

      return message
    rescue ArgumentError
      return "Sorry, couldn't find #{query}."
    end

    def get_forcast(query)
      data = WeatherUnderground::Base.new.CurrentObservations(query)
      weather = [ data.display_location.first.full,
                  data.temp_f,
                  data.weather.downcase,
                  Time.parse(data.observation_time).ago.to_words ]
      return weather
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cinch-weatherman-1.0.0 lib/cinch/plugins/weatherman/weatherman.rb