lita-onewheel-forecast-io 0.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.travis.yml +14 -0
- data/Gemfile +2 -0
- data/LICENSE +19 -0
- data/README.md +37 -0
- data/Rakefile +6 -0
- data/lib/lita-onewheel-forecast-io.rb +7 -0
- data/lib/lita/handlers/constants.rb +137 -0
- data/lib/lita/handlers/forecasts.rb +376 -0
- data/lib/lita/handlers/irc_handlers.rb +177 -0
- data/lib/lita/handlers/location.rb +13 -0
- data/lib/lita/handlers/onewheel_forecast_io.rb +165 -0
- data/lib/lita/handlers/utils.rb +396 -0
- data/lita-onewheel-forecast-io.gemspec +36 -0
- data/lita_config_sample.rb +9 -0
- data/locales/en.yml +4 -0
- data/spec/heavy_rain.json +1578 -0
- data/spec/lita/handlers/forecast_io_spec.rb +371 -0
- data/spec/mock_weather.json +1519 -0
- data/spec/mock_weather_no_minute.json +1204 -0
- data/spec/mock_weather_with_snow.json +1649 -0
- data/spec/spec_helper.rb +15 -0
- metadata +231 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3dbf02360cbc737e4e2a5b496143ea702619dcd8
|
4
|
+
data.tar.gz: e840358c5319946eef3de1fac1b9841a8be18f41
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2a035aca2c39995766079cd2d4e0ae7fed07ca2b7a901dac531542708301afc25d33bbaa7e72d4110d89d5f2ca4900fc7c6caf376f087d07fddb631dd9bef508
|
7
|
+
data.tar.gz: 085c4b590e1f0f3833e85dfaf668642c71752d69dda1b82bf12689c9a30143a452a0495c51afea0ece4aea519ba93677b1f94e4886b5f29ed2ab9a7aaca37c7d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Andrew Kreps
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# lita-onewheel-forecast-io
|
2
|
+
|
3
|
+
[](https://travis-ci.org/onewheelskyward/lita-onewheel-forecast-io)
|
4
|
+
[](https://coveralls.io/r/onewheelskyward/lita-onewheel-forecast-io)
|
5
|
+
[](https://readthedocs.org/projects/lita-onewheel-forecast-io/?badge=latest)
|
6
|
+
|
7
|
+
This Lita handler takes location-based queries and returns interesting data about the weather. Temperatures, rain chance and intensity, and wind speeds are all included. But wait, there's more! if you download now, you also get 8-ball style replies with `!rain` and `!snow`!
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add lita-onewheel-forecast-io to your Lita instance's Gemfile, from github since it's currently unpublished:
|
12
|
+
|
13
|
+
``` ruby
|
14
|
+
gem 'lita-onewheel-forecast-io', github: 'onewheelskyward/lita-onewheel-forecast-io', branch: :master
|
15
|
+
```
|
16
|
+
|
17
|
+
## Configuration
|
18
|
+
|
19
|
+
``` ruby
|
20
|
+
Lita.configure do |config|
|
21
|
+
config.handlers.onewheel_forecast_io.api_key = 'yourforecastiokey'
|
22
|
+
config.handlers.onewheel_forecast_io.api_uri = 'https://api.forecast.io/forecast/'
|
23
|
+
config.handlers.onewheel_forecast_io.colors = true
|
24
|
+
end
|
25
|
+
```
|
26
|
+
Register at https://developer.forecast.io/ to receive an API key (1000 calls/day for free). Once you have your key go ahead and toss if into your config block. Set colors to bool option of your liking. Enjoy!
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
!rain, !snow and other fine things.
|
31
|
+
|
32
|
+
## License
|
33
|
+
|
34
|
+
[MIT](http://opensource.org/licenses/MIT)
|
35
|
+
|
36
|
+
# hmm
|
37
|
+
☀ ☀ 🔥 🔥 ☼ ☼ ☼
|
data/Rakefile
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
module ForecastIo
|
2
|
+
module Constants
|
3
|
+
def scale
|
4
|
+
'f'
|
5
|
+
end
|
6
|
+
|
7
|
+
def ansi_chars
|
8
|
+
%w[_ ▁ ▃ ▅ ▇ █] # Thx, agj #pdxtech
|
9
|
+
end
|
10
|
+
|
11
|
+
def ozone_chars
|
12
|
+
%w[・ o O @ ◎ ◉]
|
13
|
+
end
|
14
|
+
|
15
|
+
def ascii_chars
|
16
|
+
%w[_ . - ~ * ']
|
17
|
+
end
|
18
|
+
|
19
|
+
# Based on the chance of precipitation.
|
20
|
+
def get_rain_range_colors
|
21
|
+
{ 0..0.10 => :blue,
|
22
|
+
0.11..0.20 => :purple,
|
23
|
+
0.21..0.30 => :teal,
|
24
|
+
0.31..0.40 => :green,
|
25
|
+
0.41..0.50 => :lime,
|
26
|
+
0.51..0.60 => :aqua,
|
27
|
+
0.61..0.70 => :yellow,
|
28
|
+
0.71..0.80 => :orange,
|
29
|
+
0.81..0.90 => :red,
|
30
|
+
0.91..1 => :pink
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
# Based on the precipIntensity field, tested mostly on Portland data. YIMV.
|
35
|
+
def get_rain_intensity_range_colors
|
36
|
+
{ 0..0.0050 => :blue,
|
37
|
+
0.0051..0.0100 => :purple,
|
38
|
+
0.0101..0.0130 => :teal,
|
39
|
+
0.0131..0.0170 => :green,
|
40
|
+
0.0171..0.0220 => :lime,
|
41
|
+
0.0221..0.0280 => :aqua,
|
42
|
+
0.0281..0.0330 => :yellow,
|
43
|
+
0.0331..0.0380 => :orange,
|
44
|
+
0.0381..0.0430 => :red,
|
45
|
+
0.0431..5 => :pink
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
# Based on the temp in F.
|
50
|
+
def get_temp_range_colors
|
51
|
+
# Absolute zero? You never know.
|
52
|
+
{ -459.7..24.99 => :blue,
|
53
|
+
25..31.99 => :purple,
|
54
|
+
32..38 => :teal,
|
55
|
+
38..45 => :green,
|
56
|
+
45..55 => :lime,
|
57
|
+
55..65 => :aqua,
|
58
|
+
65..75 => :yellow,
|
59
|
+
75..85 => :orange,
|
60
|
+
85..95 => :red,
|
61
|
+
95..99.999 => :brown,
|
62
|
+
100..159.3 => :pink
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
# Based on the wind ground speed in mph.
|
67
|
+
def get_wind_range_colors
|
68
|
+
{ 0..3 => :blue,
|
69
|
+
3..6 => :purple,
|
70
|
+
6..9 => :teal,
|
71
|
+
9..12 => :aqua,
|
72
|
+
12..15 => :yellow,
|
73
|
+
15..18 => :orange,
|
74
|
+
18..21 => :red,
|
75
|
+
21..999 => :pink,
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
# Based on the chance of sun.
|
80
|
+
def get_sun_range_colors
|
81
|
+
{ 0..0.20 => :green,
|
82
|
+
0.21..0.50 => :lime,
|
83
|
+
0.51..0.70 => :orange,
|
84
|
+
0.71..1 => :yellow
|
85
|
+
}
|
86
|
+
end
|
87
|
+
|
88
|
+
# Based on the percentage of relative humidity.
|
89
|
+
def get_humidity_range_colors
|
90
|
+
{ 0..0.12 => :blue,
|
91
|
+
0.13..0.25 => :purple,
|
92
|
+
0.26..0.38 => :teal,
|
93
|
+
0.39..0.5 => :aqua,
|
94
|
+
0.51..0.63 => :yellow,
|
95
|
+
0.64..0.75 => :orange,
|
96
|
+
0.76..0.88 => :red,
|
97
|
+
0.89..1 => :pink,
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
# IRC colors.
|
102
|
+
def colors
|
103
|
+
{ :white => '00',
|
104
|
+
:black => '01',
|
105
|
+
:blue => '02',
|
106
|
+
:green => '03',
|
107
|
+
:red => '04',
|
108
|
+
:brown => '05',
|
109
|
+
:purple => '06',
|
110
|
+
:orange => '07',
|
111
|
+
:yellow => '08',
|
112
|
+
:lime => '09',
|
113
|
+
:teal => '10',
|
114
|
+
:aqua => '11',
|
115
|
+
:royal => '12',
|
116
|
+
:pink => '13',
|
117
|
+
:grey => '14',
|
118
|
+
:silver => '15'
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
# I have no use for these yet, and yet they're handy to know.
|
123
|
+
# def attributes
|
124
|
+
# { :bold => 2.chr,
|
125
|
+
# :underlined => 31.chr,
|
126
|
+
# :underline => 31.chr,
|
127
|
+
# :reversed => 22.chr,
|
128
|
+
# :reverse => 22.chr,
|
129
|
+
# :italic => 22.chr,
|
130
|
+
# :reset => 15.chr,
|
131
|
+
# }
|
132
|
+
# end
|
133
|
+
|
134
|
+
# End constants
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,376 @@
|
|
1
|
+
module ForecastIo
|
2
|
+
module Forecasts
|
3
|
+
def ascii_rain_forecast(forecast)
|
4
|
+
str = do_the_rain_chance_thing(forecast, ascii_chars, 'precipProbability')
|
5
|
+
"rain probability #{(Time.now).strftime('%H:%M').to_s}|#{str}|#{(Time.now + 3600).strftime('%H:%M').to_s}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def ansi_rain_forecast(forecast)
|
9
|
+
str = do_the_rain_chance_thing(forecast, ansi_chars, 'precipProbability') #, 'probability', get_rain_range_colors)
|
10
|
+
max_str = get_max_rain_chance(forecast)
|
11
|
+
"rain probability #{(Time.now).strftime('%H:%M').to_s}|#{str}|#{(Time.now + 3600).strftime('%H:%M').to_s} #{max_str}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def ansi_rain_intensity_forecast(forecast)
|
15
|
+
str = do_the_rain_intensity_thing(forecast, ansi_chars, 'precipIntensity') #, 'probability', get_rain_range_colors)
|
16
|
+
"rain intensity #{(Time.now).strftime('%H:%M').to_s}|#{str}|#{(Time.now + 3600).strftime('%H:%M').to_s}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def ansi_humidity_forecast(forecast)
|
20
|
+
do_the_humidity_thing(forecast, ansi_chars, 'humidity') #, 'probability', get_rain_range_colors)
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_max_rain_chance(forecast, key = 'minutely')
|
24
|
+
unless forecast[key].nil?
|
25
|
+
data_points = []
|
26
|
+
forecast[key]['data'].each do |data_point|
|
27
|
+
data_points.push data_point['precipProbability']
|
28
|
+
end
|
29
|
+
"max #{data_points.max * 100}%"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def do_the_rain_chance_thing(forecast, chars, key, use_color = config.colors, minute_limit = nil)
|
34
|
+
if forecast['minutely'].nil?
|
35
|
+
return 'No minute-by-minute data available.'
|
36
|
+
end
|
37
|
+
|
38
|
+
i_can_has_snow = false
|
39
|
+
data_points = []
|
40
|
+
data = forecast['minutely']['data']
|
41
|
+
|
42
|
+
data.each do |datum|
|
43
|
+
data_points.push datum[key]
|
44
|
+
if datum['precipType'] == 'snow'
|
45
|
+
i_can_has_snow = true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
if minute_limit
|
50
|
+
data = condense_data(data, minute_limit)
|
51
|
+
end
|
52
|
+
|
53
|
+
str = get_dot_str(chars, data, 0, 1, key)
|
54
|
+
|
55
|
+
if i_can_has_snow
|
56
|
+
data.each_with_index do |datum, index|
|
57
|
+
if datum['precipType'] == 'snow'
|
58
|
+
str[index] = '☃'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
if use_color
|
64
|
+
str = get_colored_string(data, key, str, get_rain_range_colors)
|
65
|
+
end
|
66
|
+
|
67
|
+
str
|
68
|
+
end
|
69
|
+
|
70
|
+
def do_the_rain_intensity_thing(forecast, chars, key) #, type, range_colors = nil)
|
71
|
+
if forecast['minutely'].nil?
|
72
|
+
return 'No minute-by-minute data available.' # The "Middle of Nowhere" case.
|
73
|
+
end
|
74
|
+
|
75
|
+
data_points = []
|
76
|
+
data = forecast['minutely']['data']
|
77
|
+
|
78
|
+
data.each do |datum|
|
79
|
+
data_points.push datum[key]
|
80
|
+
end
|
81
|
+
|
82
|
+
# Fixed range graph- 0-0.11.
|
83
|
+
str = get_dot_str(chars, data, 0, 0.11, key)
|
84
|
+
|
85
|
+
if config.colors
|
86
|
+
str = get_colored_string(data, key, str, get_rain_intensity_range_colors)
|
87
|
+
end
|
88
|
+
str
|
89
|
+
end
|
90
|
+
|
91
|
+
def do_the_humidity_thing(forecast, chars, key) #, type, range_colors = nil)
|
92
|
+
data_points = []
|
93
|
+
data = forecast['hourly']['data']
|
94
|
+
|
95
|
+
data.each do |datum|
|
96
|
+
data_points.push datum[key]
|
97
|
+
end
|
98
|
+
|
99
|
+
str = get_dot_str(chars, data, 0, 1, key)
|
100
|
+
|
101
|
+
if config.colors
|
102
|
+
str = get_colored_string(data, key, str, get_humidity_range_colors)
|
103
|
+
end
|
104
|
+
"#{get_humidity data_points.first}|#{str}|#{get_humidity data_points.last} range: #{get_humidity data_points.min}-#{get_humidity data_points.max}"
|
105
|
+
end
|
106
|
+
|
107
|
+
def ansi_temp_forecast(forecast, hours = 24)
|
108
|
+
str, temperature_data = do_the_temp_thing(forecast, ansi_chars, hours)
|
109
|
+
"#{hours} hr temps: #{get_temperature temperature_data.first.round(1)} |#{str}| #{get_temperature temperature_data.last.round(1)} Range: #{get_temperature temperature_data.min.round(1)} - #{get_temperature temperature_data.max.round(1)}"
|
110
|
+
end
|
111
|
+
|
112
|
+
def ascii_temp_forecast(forecast, hours = 24)
|
113
|
+
str, temperature_data = do_the_temp_thing(forecast, ascii_chars, hours)
|
114
|
+
"#{hours} hr temps: #{get_temperature temperature_data.first.round(1)} |#{str}| #{get_temperature temperature_data.last.round(1)} Range: #{get_temperature temperature_data.min.round(1)} - #{get_temperature temperature_data.max.round(1)}"
|
115
|
+
end
|
116
|
+
|
117
|
+
def do_the_temp_thing(forecast, chars, hours)
|
118
|
+
temps = []
|
119
|
+
data = forecast['hourly']['data'].slice(0,hours - 1)
|
120
|
+
key = 'temperature'
|
121
|
+
|
122
|
+
data.each_with_index do |datum, index|
|
123
|
+
temps.push datum[key]
|
124
|
+
break if index == hours - 1 # We only want (hours) 24hrs of data.
|
125
|
+
end
|
126
|
+
|
127
|
+
differential = temps.max - temps.min
|
128
|
+
|
129
|
+
# Hmm. There's a better way.
|
130
|
+
dot_str = get_dot_str(chars, data, temps.min, differential, key)
|
131
|
+
|
132
|
+
if config.colors
|
133
|
+
dot_str = get_colored_string(data, key, dot_str, get_temp_range_colors)
|
134
|
+
end
|
135
|
+
|
136
|
+
return dot_str, temps
|
137
|
+
end
|
138
|
+
|
139
|
+
def ansi_wind_direction_forecast(forecast)
|
140
|
+
str, data = do_the_wind_direction_thing(forecast, ansi_wind_arrows)
|
141
|
+
"48h wind direction #{get_speed data.first}|#{str}|#{get_speed data.last} Range: #{get_speed(data.min)} - #{get_speed(data.max)}"
|
142
|
+
end
|
143
|
+
|
144
|
+
def ascii_wind_direction_forecast(forecast)
|
145
|
+
str, data = do_the_wind_direction_thing(forecast, ascii_wind_arrows)
|
146
|
+
"48h wind direction #{get_speed data.first}|#{str}|#{get_speed data.last} Range: #{get_speed(data.min)} - #{get_speed(data.max)}"
|
147
|
+
end
|
148
|
+
|
149
|
+
def do_the_wind_direction_thing(forecast, wind_arrows, hours = 48)
|
150
|
+
key = 'windBearing'
|
151
|
+
data = forecast['hourly']['data'].slice(0,hours - 1)
|
152
|
+
str = ''
|
153
|
+
data_points = []
|
154
|
+
|
155
|
+
data.each_with_index do |datum, index|
|
156
|
+
wind_arrow_index = get_cardinal_direction_from_bearing(datum[key])
|
157
|
+
str << wind_arrows[wind_arrow_index].to_s
|
158
|
+
data_points.push datum['windSpeed']
|
159
|
+
break if index == hours - 1 # We only want (hours) of data.
|
160
|
+
end
|
161
|
+
|
162
|
+
if config.colors
|
163
|
+
str = get_colored_string(data, 'windSpeed', str, get_wind_range_colors)
|
164
|
+
end
|
165
|
+
|
166
|
+
return str, data_points
|
167
|
+
end
|
168
|
+
|
169
|
+
def do_the_sun_thing(forecast)
|
170
|
+
key = 'cloudCover'
|
171
|
+
data_points = []
|
172
|
+
data = forecast['daily']['data']
|
173
|
+
|
174
|
+
data.each do |datum|
|
175
|
+
data_points.push (1 - datum[key]).to_f # It's a cloud cover percentage, so let's inverse it to give us sun cover.
|
176
|
+
datum[key] = (1 - datum[key]).to_f # Mod the source data for the get_dot_str call below.
|
177
|
+
end
|
178
|
+
|
179
|
+
differential = data_points.max - data_points.min
|
180
|
+
|
181
|
+
str = get_dot_str(ansi_chars, data, data_points.min, differential, key)
|
182
|
+
|
183
|
+
if config.colors
|
184
|
+
str = get_colored_string(data, key, str, get_sun_range_colors)
|
185
|
+
end
|
186
|
+
|
187
|
+
"8 day sun forecast |#{str}|"
|
188
|
+
end
|
189
|
+
|
190
|
+
def do_the_cloud_thing(forecast)
|
191
|
+
# O ◎ ]
|
192
|
+
data = forecast['hourly']['data'].slice(0,23)
|
193
|
+
|
194
|
+
str = get_dot_str(ansi_chars, data, 0, 1, 'cloudCover')
|
195
|
+
|
196
|
+
"24h cloud cover |#{str}|"
|
197
|
+
end
|
198
|
+
|
199
|
+
def do_the_sunrise_thing(forecast)
|
200
|
+
t = Time.at(fix_time(forecast['daily']['data'][0]['sunriseTime'], forecast['offset']))
|
201
|
+
t.strftime("%H:%M:%S")
|
202
|
+
end
|
203
|
+
|
204
|
+
def do_the_sunset_thing(forecast)
|
205
|
+
t = Time.at(fix_time(forecast['daily']['data'][0]['sunsetTime'], forecast['offset']))
|
206
|
+
t.strftime("%H:%M:%S")
|
207
|
+
end
|
208
|
+
|
209
|
+
def conditions(forecast)
|
210
|
+
temp_str, temps = do_the_temp_thing(forecast, ansi_chars, 8)
|
211
|
+
wind_str, winds = do_the_wind_direction_thing(forecast, ansi_wind_arrows, 8)
|
212
|
+
rain_str, rains = do_the_rain_chance_thing(forecast, ansi_chars, 'precipProbability', config.colors, 15)
|
213
|
+
|
214
|
+
sun_chance = ((1 - forecast['daily']['data'][0]['cloudCover']) * 100).round
|
215
|
+
"#{get_temperature temps.first.round(2)} |#{temp_str}| #{get_temperature temps.last.round(2)} "\
|
216
|
+
"/ #{get_speed(winds.first)} |#{wind_str}| #{get_speed(winds.last)} "\
|
217
|
+
"/ #{sun_chance}% chance of sun / 60m precip |#{rain_str}|"
|
218
|
+
end
|
219
|
+
|
220
|
+
def do_the_seven_day_thing(forecast)
|
221
|
+
mintemps = []
|
222
|
+
maxtemps = []
|
223
|
+
|
224
|
+
data = forecast['daily']['data']
|
225
|
+
data.each do |day|
|
226
|
+
mintemps.push day['temperatureMin']
|
227
|
+
maxtemps.push day['temperatureMax']
|
228
|
+
end
|
229
|
+
|
230
|
+
differential = maxtemps.max - maxtemps.min
|
231
|
+
max_str = get_dot_str(ansi_chars, data, maxtemps.min, differential, 'temperatureMax')
|
232
|
+
|
233
|
+
differential = mintemps.max - mintemps.min
|
234
|
+
min_str = get_dot_str(ansi_chars, data, mintemps.min, differential, 'temperatureMin')
|
235
|
+
|
236
|
+
if config.colors
|
237
|
+
max_str = get_colored_string(data, 'temperatureMax', max_str, get_temp_range_colors)
|
238
|
+
min_str = get_colored_string(data, 'temperatureMin', min_str, get_temp_range_colors)
|
239
|
+
end
|
240
|
+
|
241
|
+
"7day high/low temps #{get_temperature maxtemps.first.to_f.round(1)} |#{max_str}| #{get_temperature maxtemps.last.to_f.round(1)} "\
|
242
|
+
"/ #{get_temperature mintemps.first.to_f.round(1)} |#{min_str}| #{get_temperature mintemps.last.to_f.round(1)} "\
|
243
|
+
"Range: #{get_temperature mintemps.min} - #{get_temperature maxtemps.max}"
|
244
|
+
end
|
245
|
+
|
246
|
+
def do_the_seven_day_rain_thing(forecast)
|
247
|
+
precip_type = 'rain'
|
248
|
+
rains = []
|
249
|
+
|
250
|
+
data = forecast['daily']['data']
|
251
|
+
data.each do |day|
|
252
|
+
if day['precipType'] == 'snow'
|
253
|
+
precip_type = 'snow'
|
254
|
+
end
|
255
|
+
rains.push day['precipProbability']
|
256
|
+
end
|
257
|
+
|
258
|
+
str = get_dot_str(ansi_chars, data, 0, 1, 'precipProbability')
|
259
|
+
|
260
|
+
if config.colors
|
261
|
+
str = get_colored_string(data, 'precipProbability', str, get_rain_range_colors)
|
262
|
+
end
|
263
|
+
|
264
|
+
"7day #{precip_type}s |#{str}|"
|
265
|
+
end
|
266
|
+
|
267
|
+
def do_the_daily_rain_thing(forecast)
|
268
|
+
precip_type = 'rain'
|
269
|
+
rains = []
|
270
|
+
|
271
|
+
data = forecast['hourly']['data']
|
272
|
+
data.each do |day|
|
273
|
+
if day['precipType'] == 'snow'
|
274
|
+
precip_type = 'snow'
|
275
|
+
end
|
276
|
+
rains.push day['precipProbability']
|
277
|
+
end
|
278
|
+
|
279
|
+
str = get_dot_str(ansi_chars, data, 0, 1, 'precipProbability')
|
280
|
+
|
281
|
+
if config.colors
|
282
|
+
str = get_colored_string(data, 'precipProbability', str, get_rain_range_colors)
|
283
|
+
end
|
284
|
+
|
285
|
+
max_str = get_max_rain_chance(forecast, 'hourly')
|
286
|
+
|
287
|
+
"48 hr #{precip_type}s |#{str}| #{max_str}"
|
288
|
+
end
|
289
|
+
|
290
|
+
def do_the_daily_wind_thing(forecast)
|
291
|
+
winds = []
|
292
|
+
|
293
|
+
data = forecast['daily']['data']
|
294
|
+
data.each do |day|
|
295
|
+
winds.push day['windSpeed']
|
296
|
+
end
|
297
|
+
|
298
|
+
str = get_dot_str(ansi_chars, data, 0, winds.max, 'windSpeed')
|
299
|
+
|
300
|
+
if config.colors
|
301
|
+
str = get_colored_string(data, 'windSpeed', str, get_wind_range_colors)
|
302
|
+
end
|
303
|
+
|
304
|
+
"7day winds #{get_speed winds.first}|#{str}|#{get_speed winds.last} range #{get_speed winds.min}-#{get_speed winds.max}"
|
305
|
+
end
|
306
|
+
|
307
|
+
def do_the_daily_humidity_thing(forecast)
|
308
|
+
humidities = []
|
309
|
+
|
310
|
+
data = forecast['daily']['data']
|
311
|
+
data.each do |day|
|
312
|
+
humidities.push day['humidity']
|
313
|
+
end
|
314
|
+
|
315
|
+
str = get_dot_str(ansi_chars, data, 0, 1, 'humidity')
|
316
|
+
|
317
|
+
if config.colors
|
318
|
+
str = get_colored_string(data, 'humidity', str, get_wind_range_colors)
|
319
|
+
end
|
320
|
+
|
321
|
+
"7day humidity #{get_humidity humidities.first}|#{str}|#{get_humidity humidities.last} "\
|
322
|
+
"range #{get_humidity humidities.min}-#{get_humidity humidities.max}"
|
323
|
+
end
|
324
|
+
|
325
|
+
def do_the_ozone_thing(forecast)
|
326
|
+
# O ◎ ]
|
327
|
+
data = forecast['hourly']['data']
|
328
|
+
|
329
|
+
str = get_dot_str(ozone_chars, data, 280, 350-280, 'ozone')
|
330
|
+
|
331
|
+
"ozones #{data.first['ozone']} |#{str}| #{data.last['ozone']} [24h forecast]"
|
332
|
+
end
|
333
|
+
|
334
|
+
def do_the_pressure_thing(forecast)
|
335
|
+
data = forecast['hourly']['data']
|
336
|
+
key = 'pressure'
|
337
|
+
boiled_data = []
|
338
|
+
|
339
|
+
data.each do |d|
|
340
|
+
boiled_data.push d[key]
|
341
|
+
end
|
342
|
+
|
343
|
+
str = get_dot_str(ansi_chars, data, boiled_data.min, boiled_data.max - boiled_data.min, key)
|
344
|
+
|
345
|
+
"pressure #{data.first[key]} hPa |#{str}| #{data.last[key]} hPa range: #{boiled_data.min}-#{boiled_data.max} hPa [48h forecast]"
|
346
|
+
end
|
347
|
+
|
348
|
+
def do_the_daily_pressure_thing(forecast)
|
349
|
+
# O ◎ ]
|
350
|
+
data = forecast['daily']['data']
|
351
|
+
key = 'pressure'
|
352
|
+
boiled_data = []
|
353
|
+
|
354
|
+
data.each do |d|
|
355
|
+
boiled_data.push d[key]
|
356
|
+
end
|
357
|
+
|
358
|
+
str = get_dot_str(ansi_chars, data, boiled_data.min, boiled_data.max - boiled_data.min, key)
|
359
|
+
|
360
|
+
"pressure #{data.first[key]} hPa |#{str}| #{data.last[key]} hPa range: #{boiled_data.min}-#{boiled_data.max} hPa [8 day forecast]"
|
361
|
+
end
|
362
|
+
|
363
|
+
def get_alerts(forecast)
|
364
|
+
str = ''
|
365
|
+
forecast['alerts'].each do |alert|
|
366
|
+
alert['description'].match /\.\.\.(\w+)\.\.\./
|
367
|
+
str += "#{alert['uri']}\n"
|
368
|
+
end
|
369
|
+
str
|
370
|
+
end
|
371
|
+
|
372
|
+
def do_the_nearest_storm_thing(forecast)
|
373
|
+
return forecast['currently']['nearestStormDistance'], forecast['currently']['nearestStormBearing']
|
374
|
+
end
|
375
|
+
end
|
376
|
+
end
|