cinch-forecast 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/README.md +1 -4
- data/Rakefile +1 -0
- data/VERSION +1 -0
- data/cinch-forecast.gemspec +2 -2
- data/lib/cinch/plugins/forecast.rb +46 -43
- metadata +10 -6
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -1,7 +1,4 @@
|
|
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
|
-
|
4
|
-
Cinch::Forecast
|
1
|
+
Cinch::Forecast [![Gem Version](https://badge.fury.io/rb/cinch-forecast.png)](http://badge.fury.io/rb/cinch-forecast) [![Dependency Status](https://gemnasium.com/jonahoffline/cinch-forecast.png)](https://gemnasium.com/jonahoffline/cinch-forecast) [![Code Climate](https://codeclimate.com/github/jonahoffline/cinch-forecast.png)](https://codeclimate.com/github/jonahoffline/cinch-forecast)
|
5
2
|
=================
|
6
3
|
|
7
4
|
Forecast is a Cinch plugin for getting the weather forecast.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.3
|
data/cinch-forecast.gemspec
CHANGED
@@ -12,11 +12,11 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.homepage = 'https://github.com/jonahoffline/cinch-forecast'
|
13
13
|
spec.license = 'MIT'
|
14
14
|
|
15
|
-
spec.files =
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
16
|
spec.require_paths = ['lib']
|
17
17
|
spec.required_ruby_version = '>= 1.9.3'
|
18
18
|
|
19
|
-
spec.add_dependency 'cinch', '~> 2.0.
|
19
|
+
spec.add_dependency 'cinch', '~> 2.0.5'
|
20
20
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
21
21
|
spec.add_development_dependency 'rake'
|
22
22
|
end
|
@@ -5,26 +5,31 @@ require 'json'
|
|
5
5
|
|
6
6
|
module Cinch
|
7
7
|
module Plugins
|
8
|
+
# Forecast is a Cinch plugin for getting the weather forecast.
|
9
|
+
# @author Jonah Ruiz <jonah@pixelhipsters.com>
|
8
10
|
class Forecast
|
9
11
|
include Cinch::Plugin
|
10
12
|
|
11
13
|
match /forecast (.+)/
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
# Executes the geolookup and get_conditions method when Regexp is matched
|
15
|
+
#
|
16
|
+
# @param msg [Cinch::Bot] passed internally by the framework.
|
17
|
+
# @param query [String] zipcode captured by the match method.
|
18
|
+
# @return [String] weather summary to IRC channel.
|
19
|
+
def execute(msg, query)
|
15
20
|
location = geolookup(query)
|
16
|
-
return
|
21
|
+
return msg.reply "No results found for #{query}." if location.nil?
|
17
22
|
|
18
|
-
##
|
19
|
-
# Gets the weather conditions
|
20
23
|
data = get_conditions(location)
|
21
|
-
return
|
24
|
+
return msg.reply 'Problem getting data. Try again later.' if data.nil?
|
22
25
|
|
23
|
-
|
24
|
-
# Returns the weather summary
|
25
|
-
m.reply(weather_summary(data))
|
26
|
+
msg.reply(weather_summary(data))
|
26
27
|
end
|
27
28
|
|
29
|
+
# Finds location for zipcode
|
30
|
+
#
|
31
|
+
# @param zipcode [String] zipcode
|
32
|
+
# @return [String] location-specific parameter for getting conditions.
|
28
33
|
def geolookup(zipcode)
|
29
34
|
location = JSON.parse(open("http://api.wunderground.com/api/#{ENV['WUNDERGROUND_KEY']}/geolookup/q/#{zipcode}.json").read)
|
30
35
|
location['location']['l']
|
@@ -32,50 +37,48 @@ module Cinch
|
|
32
37
|
nil
|
33
38
|
end
|
34
39
|
|
40
|
+
# Fetches weather conditions and formats output
|
41
|
+
#
|
42
|
+
# @param location [String] provided by the geolookup method
|
43
|
+
# @return [OpenStruct] parsed weather conditions.
|
35
44
|
def get_conditions(location)
|
36
|
-
data
|
45
|
+
data = JSON.parse(open("http://api.wunderground.com/api/#{ENV['WUNDERGROUND_KEY']}/conditions#{location}.json").read)
|
46
|
+
current = data['current_observation']
|
47
|
+
location_data = current['display_location']
|
37
48
|
|
38
|
-
##
|
39
|
-
# Clean up and return as an OpenStruct
|
40
49
|
OpenStruct.new(
|
41
|
-
|
42
|
-
|
43
|
-
county: data['current_observation']['display_location']['full'],
|
44
|
-
country: data['current_observation']['display_location']['country'],
|
50
|
+
county: location_data['full'],
|
51
|
+
country: location_data['country'],
|
45
52
|
|
46
|
-
|
47
|
-
|
48
|
-
lat: data['current_observation']['display_location']['latitude'],
|
49
|
-
lng: data['current_observation']['display_location']['longitude'],
|
53
|
+
lat: location_data['latitude'],
|
54
|
+
lng: location_data['longitude'],
|
50
55
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
feels_like: data['current_observation']['feelslike_string'],
|
59
|
-
uv: data['current_observation']['UV'],
|
56
|
+
observation_time: current['observation_time'],
|
57
|
+
weather: current['weather'],
|
58
|
+
temp_fahrenheit: current['temp_f'],
|
59
|
+
temp_celcius: current['temp_c'],
|
60
|
+
relative_humidity: current['relative_humidity'],
|
61
|
+
feels_like: current['feelslike_string'],
|
62
|
+
uv_level: current['UV'],
|
60
63
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
wind_kph: data['current_observation']['wind_kph'],
|
69
|
-
pressure_mb: data['current_observation']['pressure_mb'],
|
64
|
+
wind: current['wind_string'],
|
65
|
+
wind_direction: current['wind_dir'],
|
66
|
+
wind_degrees: current['wind_degrees'],
|
67
|
+
wind_mph: current['wind_mph'],
|
68
|
+
wind_gust_mph: current['wind_gust_mph'],
|
69
|
+
wind_kph: current['wind_kph'],
|
70
|
+
pressure_mb: current['pressure_mb'],
|
70
71
|
|
71
|
-
|
72
|
-
# Forecast URL
|
73
|
-
forecast_url: data['current_observation']['forecast_url']
|
72
|
+
forecast_url: current['forecast_url']
|
74
73
|
)
|
75
74
|
rescue
|
76
75
|
nil
|
77
76
|
end
|
78
77
|
|
78
|
+
# Displays weather summary for IRC output
|
79
|
+
#
|
80
|
+
# @param data [OpenStruct] weather conditions data
|
81
|
+
# @return [String] weather summary.
|
79
82
|
def weather_summary(data)
|
80
83
|
##
|
81
84
|
# Sample Summary using !forecast 00687
|
@@ -92,7 +95,7 @@ module Cinch
|
|
92
95
|
Forecast for: #{data.county}, #{data.country}
|
93
96
|
Latitude: #{data.lat}, Longitude: #{data.lng}
|
94
97
|
Weather is #{data.weather}, #{data.feels_like}
|
95
|
-
UV: #{data.
|
98
|
+
UV: #{data.uv_level}, Humidity: #{data.relative_humidity}
|
96
99
|
Wind: #{data.wind}
|
97
100
|
Direction: #{data.wind_direction}, Degrees: #{data.wind_degrees},
|
98
101
|
#{data.observation_time}
|
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.3
|
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-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cinch
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 2.0.
|
21
|
+
version: 2.0.5
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 2.0.
|
29
|
+
version: 2.0.5
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: bundler
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,10 +66,14 @@ executables: []
|
|
66
66
|
extensions: []
|
67
67
|
extra_rdoc_files: []
|
68
68
|
files:
|
69
|
-
-
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
70
71
|
- LICENSE.txt
|
71
72
|
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- VERSION
|
72
75
|
- cinch-forecast.gemspec
|
76
|
+
- lib/cinch/plugins/forecast.rb
|
73
77
|
homepage: https://github.com/jonahoffline/cinch-forecast
|
74
78
|
licenses:
|
75
79
|
- MIT
|
@@ -91,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
95
|
version: '0'
|
92
96
|
segments:
|
93
97
|
- 0
|
94
|
-
hash:
|
98
|
+
hash: 2054927745430645094
|
95
99
|
requirements: []
|
96
100
|
rubyforge_project:
|
97
101
|
rubygems_version: 1.8.25
|