cinch-forecast 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jonah Ruiz
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ Cinch::Forecast
2
+ =================
3
+
4
+ Forecast is a Cinch plugin for getting the weather forecast.
5
+
6
+ Installation
7
+ ---------------------
8
+
9
+ $ gem install cinch-forecast
10
+
11
+ Setup
12
+ -------
13
+
14
+ You will need a Wunderground API key. You can sign-up for a free one at
15
+ [Wunderground](http://www.wunderground.com/weather/api/)
16
+
17
+ #### Configuration ####
18
+
19
+ Set your key as an environment variable:
20
+
21
+ $ export WUNDERGROUND_KEY='your_api_key_here'
22
+
23
+ You could also save it in your ~/.bash_profile
24
+
25
+ #### Command ####
26
+
27
+ * !forecast [zipcode] - Fetches the weather forecast for zipcode.
28
+
29
+ ## Integration with Cinch ##
30
+
31
+ ```ruby
32
+ require 'cinch'
33
+ require 'cinch/plugins/forecast'
34
+
35
+ bot = Cinch::Bot.new do
36
+ configure do |c|
37
+ c.server = 'irc.freenode.net'
38
+ c.nick = 'Tabin_Pumarejo'
39
+ c.channels = ['#RubyOnADHD']
40
+ c.plugins.plugins = [Cinch::Plugins::Forecast]
41
+ end
42
+ end
43
+
44
+ bot.start
45
+ ```
46
+
47
+ Enjoy!
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'cinch-forecast'
7
+ spec.version = File.new('VERSION', 'r').read.chomp
8
+ spec.authors = ['Jonah Ruiz']
9
+ spec.email = ['jonah@pixelhipsters.com']
10
+ spec.description = %q{Forecast is a Cinch plugin for getting the weather forecast}
11
+ spec.summary = %q{Cinch plugin for getting the weather forecast by zipcode}
12
+ spec.homepage = 'https://github.com/jonahoffline/cinch-forecast'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = Dir['{lib}/**/*','LICENSE.txt', 'README.md', 'cinch-forecast.gemspec']
16
+ spec.require_paths = ['lib']
17
+ spec.required_ruby_version = '>= 1.9.3'
18
+
19
+ spec.add_dependency 'cinch', '~> 2.0.4'
20
+ spec.add_development_dependency 'bundler', '~> 1.3'
21
+ spec.add_development_dependency 'rake'
22
+ end
@@ -0,0 +1,115 @@
1
+ require 'cinch'
2
+ require 'ostruct'
3
+ require 'open-uri'
4
+ require 'json'
5
+
6
+ module Cinch
7
+ module Plugins
8
+ class Forecast
9
+ include Cinch::Plugin
10
+
11
+ API_KEY = ENV['WUNDERGROUND_KEY']
12
+ BASE_URL = "http://api.wunderground.com/api/#{API_KEY}/"
13
+
14
+
15
+ match /forecast (.+)/
16
+
17
+ attr_accessor :location, :conditions
18
+
19
+ def execute(m, query)
20
+ @location, @conditions = nil, {}
21
+
22
+ geolookup(query)
23
+ get_conditions
24
+
25
+ ##
26
+ # Reply with the Weather Summary
27
+ m.reply(weather_summary)
28
+ end
29
+
30
+ def geolookup(zipcode)
31
+ results = open("#{BASE_URL}geolookup/q/#{zipcode}.json").read
32
+ data = JSON.parse(results)
33
+ @location = data['location']['l']
34
+ rescue
35
+ "No results found for #{zipcode}"
36
+ end
37
+
38
+ def get_conditions
39
+ results = open("#{BASE_URL}conditions#{@location}.json").read
40
+
41
+ ##
42
+ # Cleanup and store into Hash
43
+ clean_up(JSON.parse(results))
44
+ rescue
45
+ 'No weather data was found.'
46
+ end
47
+
48
+ def clean_up(data)
49
+ ##
50
+ # County, State & Country
51
+ @conditions.store(:county, data['current_observation']['display_location']['full'])
52
+ @conditions.store(:country, data['current_observation']['display_location']['country'])
53
+
54
+ ##
55
+ # Latitude and Longitude
56
+ @conditions.store(:lat, data['current_observation']['display_location']['latitude'])
57
+ @conditions.store(:lng, data['current_observation']['display_location']['longitude'])
58
+
59
+ ##
60
+ # Observation Time
61
+ @conditions.store(:observation_time, data['current_observation']['observation_time'])
62
+
63
+ ##
64
+ # General Weather Information
65
+ @conditions.store(:weather, data['current_observation']['weather'])
66
+ @conditions.store(:temp_fahrenheit, data['current_observation']['temp_f'])
67
+ @conditions.store(:temp_celcius, data['current_observation']['temp_c'])
68
+ @conditions.store(:relative_humidity, data['current_observation']['relative_humidity'])
69
+ @conditions.store(:feels_like, data['current_observation']['feelslike_string'])
70
+ @conditions.store(:uv, data['current_observation']['UV'])
71
+
72
+ ##
73
+ # Wind Related Data
74
+ @conditions.store(:wind, data['current_observation']['wind_string'])
75
+ @conditions.store(:wind_direction, data['current_observation']['wind_dir'])
76
+ @conditions.store(:wind_degrees, data['current_observation']['wind_degrees'])
77
+ @conditions.store(:wind_mph, data['current_observation']['wind_mph'])
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)
88
+ rescue
89
+ 'Problem getting data.'
90
+ end
91
+
92
+ def weather_summary
93
+ ##
94
+ # Sample Summary using geolookup('00687')
95
+ # Weather for: Morovis, PR, US
96
+ # Party Cloudy, feels like 85 F (27.1 C)
97
+ # UV: 9.5, Humidity: 78%
98
+ # Wind: From the SE at 1.0 MPH Gusting to 5.0 MPH
99
+ # Direction: East, Degrees: 90
100
+ # Last Updated on June 4, 11:25 PM AST
101
+ # More Info: http://www.wunderground.com/US/PR/Morovis.html
102
+
103
+ %Q{Weather for: #{@conditions.county}, #{@conditions.country}
104
+ #{@conditions.weather}, #{@conditions.feels_like}
105
+ UV: #{@conditions.uv}, Humidity: #{@conditions.relative_humidity}
106
+ Wind: #{@conditions.wind}
107
+ Direction: #{@conditions.wind_direction}, Degrees: #{@conditions.wind_degrees},
108
+ #{@conditions.observation_time}
109
+ More Info: #{@conditions.forecast_url}}
110
+ rescue
111
+ 'Problem fetching the weather summary.'
112
+ end
113
+ end
114
+ end
115
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cinch-forecast
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jonah Ruiz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cinch
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.4
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.4
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Forecast is a Cinch plugin for getting the weather forecast
63
+ email:
64
+ - jonah@pixelhipsters.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - lib/cinch/plugins/forecast.rb
70
+ - LICENSE.txt
71
+ - README.md
72
+ - cinch-forecast.gemspec
73
+ homepage: https://github.com/jonahoffline/cinch-forecast
74
+ licenses:
75
+ - MIT
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 1.9.3
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ segments:
93
+ - 0
94
+ hash: 2530530863438312584
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 1.8.25
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Cinch plugin for getting the weather forecast by zipcode
101
+ test_files: []