Class: Plugins::WeatherHurricane

Inherits:
Object
  • Object
show all
Includes:
Cinch::Helpers, Cinch::Plugin
Defined in:
lib/Zeta/plugins/weather_almanac.rb,
lib/Zeta/plugins/weather_hurricane.rb

Overview

Forecast is a Cinch plugin for getting the weather forecast.

Author:

Instance Method Summary collapse

Methods included from Cinch::Plugin

#check?, #log2chan

Instance Method Details

#almanac(msg, locale) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/Zeta/plugins/weather_almanac.rb', line 24

def almanac(msg, locale)
  autocomplete = JSON.parse(open(URI.encode("http://autocomplete.wunderground.com/aq?query=#{locale}")).read)
  url = URI.encode("http://api.wunderground.com/api/#{Config.secrets[:wunderground]}/almanac/#{autocomplete['RESULTS'][0]['l']}.json")
  location = JSON.parse(
      # RestClient.get(url)
      open(url).read
  )
  return msg.reply "No results found for #{query}." if location.nil?

  time = Time.now()

  data = OpenStruct.new(
      date: time.strftime('%B, %d %Y (%A) '),
      airport: location['almanac']['airport_code'],
      high_norm_f: location['almanac']['temp_high']['normal']['F'],
      high_norm_c: location['almanac']['temp_high']['normal']['C'],
      high_record_y: location['almanac']['temp_high']['recordyear'],
      high_record_f: location['almanac']['temp_high']['record']['F'],
      high_record_c: location['almanac']['temp_high']['normal']['C'],
      low_norm_f: location['almanac']['temp_low']['normal']['F'],
      low_norm_c: location['almanac']['temp_low']['normal']['C'],
      low_record_y: location['almanac']['temp_low']['recordyear'],
      low_record_f: location['almanac']['temp_low']['record']['F'],
      low_record_c: location['almanac']['temp_low']['normal']['C'],
      )

  reply_msg = "∴ Almanac #{data.date} ≈ Airport #{data.airport} " \
          "≈ Normal #{data.high_norm_f} F (#{data.high_norm_c} C) | #{data.low_norm_f} F (#{data.low_norm_c} C) " \
          "≈ High #{data.high_record_f} F (#{data.high_record_c} C) [#{data.high_record_y}] " \
          "≈ Low #{data.low_record_f} F (#{data.low_record_c} C) [#{data.low_record_y}] ∴"

  msg.reply(reply_msg)
end

#hurricane(msg) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/Zeta/plugins/weather_hurricane.rb', line 23

def hurricane(msg)
  url = URI.encode "http://api.wunderground.com/api/#{Zsec.wunderground}/currenthurricane/view.json"
  location = JSON.parse(
      # RestClient.get(url)
      open(url).read
  )
  return msg.reply "No results found for #{query}." if location.nil?
  reply_msg = "#{location['currenthurricane'][0]['stormInfo']['stormName_Nice']} " \
              "(#{location['currenthurricane'][0]['stormInfo']['stormNumber']}) "\
              "≈ Category #{location['currenthurricane'][0]['Current']['SaffirSimpsonCategory']} " \
              "≈ Wind #{location['currenthurricane'][0]['Current']['WindSpeed']['Mph']} mph " \
              "(#{location['currenthurricane'][0]['Current']['WindSpeed']['Kph']} kph) " \
              "≈ Wind Gust #{location['currenthurricane'][0]['Current']['WindGust']['Mph']} mph " \
              "(#{location['currenthurricane'][0]['Current']['WindGust']['Kph']} kph) " \
              "#{location['currenthurricane'][0]['Current']['Time']['pretty']}"
  msg.reply(reply_msg)
end