cinch-forecast 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -1
- data/lib/cinch/plugins/forecast.rb +67 -77
- metadata +3 -3
data/README.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/cinch-forecast.png)](http://badge.fury.io/rb/cinch-forecast)
|
2
|
+
[![Dependency Status](https://gemnasium.com/jonahoffline/cinch-forecast.png)](https://gemnasium.com/jonahoffline/cinch-forecast)
|
3
|
+
|
1
4
|
Cinch::Forecast
|
2
5
|
=================
|
3
6
|
|
@@ -35,7 +38,7 @@ require 'cinch/plugins/forecast'
|
|
35
38
|
bot = Cinch::Bot.new do
|
36
39
|
configure do |c|
|
37
40
|
c.server = 'irc.freenode.net'
|
38
|
-
c.nick = '
|
41
|
+
c.nick = 'Tavin_Pumarejo'
|
39
42
|
c.channels = ['#RubyOnADHD']
|
40
43
|
c.plugins.plugins = [Cinch::Plugins::Forecast]
|
41
44
|
end
|
@@ -46,6 +49,9 @@ bot.start
|
|
46
49
|
|
47
50
|
Enjoy!
|
48
51
|
|
52
|
+
## Author
|
53
|
+
* [Jonah Ruiz](http://www.pixelhipsters.com)
|
54
|
+
|
49
55
|
## Contributing
|
50
56
|
|
51
57
|
1. Fork it
|
@@ -8,107 +8,97 @@ module Cinch
|
|
8
8
|
class Forecast
|
9
9
|
include Cinch::Plugin
|
10
10
|
|
11
|
-
API_KEY = ENV['WUNDERGROUND_KEY']
|
12
|
-
BASE_URL = "http://api.wunderground.com/api/#{API_KEY}/"
|
13
|
-
|
14
|
-
|
15
11
|
match /forecast (.+)/
|
16
|
-
|
17
|
-
attr_accessor :location, :conditions
|
18
|
-
|
19
12
|
def execute(m, query)
|
20
|
-
|
13
|
+
##
|
14
|
+
# Gets location using zipcode
|
15
|
+
location = geolookup(query)
|
16
|
+
return m.reply "No results found for #{query}." if location.nil?
|
21
17
|
|
22
|
-
|
23
|
-
|
18
|
+
##
|
19
|
+
# Gets the weather conditions
|
20
|
+
data = get_conditions(location)
|
21
|
+
return m.reply 'Problem getting data. Try again later.' if data.nil?
|
24
22
|
|
25
23
|
##
|
26
|
-
#
|
27
|
-
m.reply(weather_summary)
|
24
|
+
# Returns the weather summary
|
25
|
+
m.reply(weather_summary(data))
|
28
26
|
end
|
29
27
|
|
30
28
|
def geolookup(zipcode)
|
31
|
-
|
32
|
-
|
33
|
-
@location = data['location']['l']
|
29
|
+
location = JSON.parse(open("http://api.wunderground.com/api/#{ENV['WUNDERGROUND_KEY']}/geolookup/q/#{zipcode}.json").read)
|
30
|
+
location['location']['l']
|
34
31
|
rescue
|
35
|
-
|
32
|
+
nil
|
36
33
|
end
|
37
34
|
|
38
|
-
def get_conditions
|
39
|
-
|
35
|
+
def get_conditions(location)
|
36
|
+
data = JSON.parse(open("http://api.wunderground.com/api/#{ENV['WUNDERGROUND_KEY']}/conditions#{location}.json").read)
|
40
37
|
|
41
38
|
##
|
42
|
-
#
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
@conditions.store(:wind_gust_mph, data['current_observation']['wind_gust_mph'])
|
79
|
-
@conditions.store(:wind_kph, data['current_observation']['wind_kph'])
|
80
|
-
@conditions.store(:pressure_mb, data['current_observation']['pressure_mb'])
|
81
|
-
|
82
|
-
##
|
83
|
-
# Forecast URL
|
84
|
-
@conditions.store(:forecast_url, data['current_observation']['forecast_url'])
|
85
|
-
@conditions.store(:fetched_from, "#{BASE_URL}conditions#{@location}.json")
|
86
|
-
|
87
|
-
@conditions = OpenStruct.new(@conditions)
|
39
|
+
# Clean up and return as an OpenStruct
|
40
|
+
OpenStruct.new(
|
41
|
+
##
|
42
|
+
# County, State & Country
|
43
|
+
county: data['current_observation']['display_location']['full'],
|
44
|
+
country: data['current_observation']['display_location']['country'],
|
45
|
+
|
46
|
+
##
|
47
|
+
# Latitude and Longitude
|
48
|
+
lat: data['current_observation']['display_location']['latitude'],
|
49
|
+
lng: data['current_observation']['display_location']['longitude'],
|
50
|
+
|
51
|
+
##
|
52
|
+
# Observation Time and General Weather Information
|
53
|
+
observation_time: data['current_observation']['observation_time'],
|
54
|
+
weather: data['current_observation']['weather'],
|
55
|
+
temp_fahrenheit: data['current_observation']['temp_f'],
|
56
|
+
temp_celcius: data['current_observation']['temp_c'],
|
57
|
+
relative_humidity: data['current_observation']['relative_humidity'],
|
58
|
+
feels_like: data['current_observation']['feelslike_string'],
|
59
|
+
uv: data['current_observation']['UV'],
|
60
|
+
|
61
|
+
##
|
62
|
+
# Wind Related Data
|
63
|
+
wind: data['current_observation']['wind_string'],
|
64
|
+
wind_direction: data['current_observation']['wind_dir'],
|
65
|
+
wind_degrees: data['current_observation']['wind_degrees'],
|
66
|
+
wind_mph: data['current_observation']['wind_mph'],
|
67
|
+
wind_gust_mph: data['current_observation']['wind_gust_mph'],
|
68
|
+
wind_kph: data['current_observation']['wind_kph'],
|
69
|
+
pressure_mb: data['current_observation']['pressure_mb'],
|
70
|
+
|
71
|
+
##
|
72
|
+
# Forecast URL
|
73
|
+
forecast_url: data['current_observation']['forecast_url']
|
74
|
+
)
|
88
75
|
rescue
|
89
|
-
|
76
|
+
nil
|
90
77
|
end
|
91
78
|
|
92
|
-
def weather_summary
|
79
|
+
def weather_summary(data)
|
93
80
|
##
|
94
|
-
# Sample Summary using
|
95
|
-
#
|
96
|
-
#
|
81
|
+
# Sample Summary using !forecast 00687
|
82
|
+
# Forecast for: Morovis, PR, US
|
83
|
+
# Latitude: 18.32682228, Longitude: -66.40519714
|
84
|
+
# Weather is Partly Cloudy, feels like 85 F (27.1 C)
|
97
85
|
# UV: 9.5, Humidity: 78%
|
98
86
|
# Wind: From the SE at 1.0 MPH Gusting to 5.0 MPH
|
99
87
|
# Direction: East, Degrees: 90
|
100
88
|
# Last Updated on June 4, 11:25 PM AST
|
101
89
|
# More Info: http://www.wunderground.com/US/PR/Morovis.html
|
102
90
|
|
103
|
-
%Q{
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
91
|
+
%Q{
|
92
|
+
Forecast for: #{data.county}, #{data.country}
|
93
|
+
Latitude: #{data.lat}, Longitude: #{data.lng}
|
94
|
+
Weather is #{data.weather}, #{data.feels_like}
|
95
|
+
UV: #{data.uv}, Humidity: #{data.relative_humidity}
|
96
|
+
Wind: #{data.wind}
|
97
|
+
Direction: #{data.wind_direction}, Degrees: #{data.wind_degrees},
|
98
|
+
#{data.observation_time}
|
99
|
+
More Info: #{data.forecast_url}}
|
110
100
|
rescue
|
111
|
-
'Problem fetching the weather summary.'
|
101
|
+
'Problem fetching the weather summary. Try again later.'
|
112
102
|
end
|
113
103
|
end
|
114
104
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch-forecast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cinch
|
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
91
|
version: '0'
|
92
92
|
segments:
|
93
93
|
- 0
|
94
|
-
hash:
|
94
|
+
hash: -2870447541984448510
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project:
|
97
97
|
rubygems_version: 1.8.25
|