lita-onewheel-forecast-io 1.6.7 → 1.13.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5a9230e0b42827da185a7d6223dccd836e1402ee10b4f97b5f10c02aa445d67
4
- data.tar.gz: 5b9d042e3e85125ac159192687a06e7e593e5cfa83c874b63cf8ef556cc8215f
3
+ metadata.gz: 132b9048f18c511b0eeb2972a6538852ac1429452a5f67ba12a562de12e77bce
4
+ data.tar.gz: 5e0889998137118390df5677d9a5f9c64071855df22ed68cb56807eb580d40ee
5
5
  SHA512:
6
- metadata.gz: 7ab819dfaa20a8ec3bfe73c8c23c09e46ec0ffb9f0b54f48e81560334ebaaeb781669af0b8d8bd52c59a044734e66777e068b5332c46c2bdd8ad9696bc3a2be4
7
- data.tar.gz: fd5a6a32285049b803c005f43da49a7eb022cd3a24d753df0bb9409ed1df4496acc487a574b4a56a342b15e6cded04239b38e45be6d557f88eb37ee3923f451a
6
+ metadata.gz: 6207a620b70030ccc8e13e510835552f6c3253111f4d3efe856dcb056138f589e53035e4f7ee5e129f24b3a29b6aa8c389e7a0e62c256f03ec186013f47a2cbd
7
+ data.tar.gz: b32b71dab4b2bafc4092b16f0d7b98127dec7c57c64d8503ec5334ca65a3d95148e750da92c8ada1ee674a132f54648c2424b982d0c47a97a2758564e81cafe7
@@ -139,7 +139,20 @@ module ForecastIo
139
139
  # }
140
140
  # end
141
141
 
142
- # End constants
143
-
142
+ def get_uvindex_colors
143
+ { 0..0 => :black,
144
+ 1..1 => :royal,
145
+ 2..2 => :brown,
146
+ 3..3 => :purple,
147
+ 4..4 => :green,
148
+ 5..5 => :lime,
149
+ 6..6 => :red,
150
+ 7..7 => :orange,
151
+ 8..8 => :yellow,
152
+ 9..9 => :aqua,
153
+ 10..10 => :pink,
154
+ 11..11 => :white
155
+ }
156
+ end
144
157
  end
145
158
  end
@@ -5,19 +5,21 @@ module ForecastIo
5
5
  def ascii_rain_forecast(forecast)
6
6
  (str, precip_type) = do_the_rain_chance_thing(forecast, ascii_chars, 'precipProbability')
7
7
  max = get_max_by_data_key(forecast, 'minutely', 'precipProbability')
8
- "1hr #{precip_type} probability #{(Time.now).strftime('%H:%M').to_s}|#{str}|#{(Time.now + 3600).strftime('%H:%M').to_s} max #{(max.to_f * 100).round(2)}%"
8
+ agg = get_aggregate_by_data_key(forecast, 'minutely', 'precipIntensity')
9
+ "1hr #{precip_type} probability #{(Time.now).strftime('%H:%M').to_s}|#{str}|#{(Time.now + 3600).strftime('%H:%M').to_s} max #{(max.to_f * 100).round(2)}%, #{get_accumulation agg} accumulation"
9
10
  end
10
11
 
11
12
  def ansi_rain_forecast(forecast)
12
13
  (str, precip_type) = do_the_rain_chance_thing(forecast, ansi_chars, 'precipProbability') #, 'probability', get_rain_range_colors)
13
14
  max = get_max_by_data_key(forecast, 'minutely', 'precipProbability')
14
- "1hr #{precip_type} probability #{(Time.now).strftime('%H:%M').to_s}|#{str}|#{(Time.now + 3600).strftime('%H:%M').to_s} max #{(max.to_f * 100).round(2)}%"
15
+ agg = get_aggregate_by_data_key(forecast, 'minutely', 'precipIntensity')
16
+ "1hr #{precip_type} probability #{(Time.now).strftime('%H:%M').to_s}|#{str}|#{(Time.now + 3600).strftime('%H:%M').to_s} max #{(max.to_f * 100).round(2)}%, #{get_accumulation agg} accumulation"
15
17
  end
16
18
 
17
19
  def ansi_rain_intensity_forecast(forecast)
18
20
  (str, precip_type) = do_the_rain_intensity_thing(forecast, ansi_chars, 'precipIntensity') #, 'probability', get_rain_range_colors)
19
- max_str = get_max_by_data_key(forecast, 'minutely', 'precipIntensity')
20
- "1hr #{precip_type} intensity #{(Time.now).strftime('%H:%M').to_s}|#{str}|#{(Time.now + 3600).strftime('%H:%M').to_s} max: #{max_str}"
21
+ agg = get_aggregate_by_data_key(forecast, 'minutely', 'precipIntensity')
22
+ "1hr #{precip_type} intensity #{(Time.now).strftime('%H:%M').to_s}|#{str}|#{(Time.now + 3600).strftime('%H:%M').to_s}, #{get_accumulation agg} accumulation"
21
23
  end
22
24
 
23
25
  def ansi_humidity_forecast(forecast)
@@ -44,6 +46,17 @@ module ForecastIo
44
46
  end
45
47
  end
46
48
 
49
+ def get_aggregate_by_data_key(forecast, key, datum)
50
+ unless forecast[key].nil?
51
+ sum = 0
52
+ forecast[key]['data'].each do |data_point|
53
+ Lita.logger.debug "Adding #{data_point[datum]} to #{sum}"
54
+ sum += data_point[datum].to_f
55
+ end
56
+ sum.round(3)
57
+ end
58
+ end
59
+
47
60
  def do_the_rain_chance_thing(forecast, chars, key, use_color = config.colors, minute_limit = nil)
48
61
  if forecast['minutely'].nil?
49
62
  return 'No minute-by-minute data available.'
@@ -132,6 +145,11 @@ module ForecastIo
132
145
  "#{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)}"
133
146
  end
134
147
 
148
+ def ansi_windchill_forecast(forecast, hours = 24)
149
+ str, temperature_data = do_the_windchill_temp_thing(forecast, ansi_chars, hours)
150
+ "#{hours} hr windchill 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)}"
151
+ end
152
+
135
153
  def ascii_temp_forecast(forecast, hours = 24)
136
154
  str, temperature_data = do_the_temp_thing(forecast, ascii_chars, hours)
137
155
  "#{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)}"
@@ -159,14 +177,43 @@ module ForecastIo
159
177
  return dot_str, temps
160
178
  end
161
179
 
180
+ def do_the_windchill_temp_thing(forecast, chars, hours)
181
+ temps = []
182
+ wind = []
183
+ data = forecast['hourly']['data'].slice(0,hours - 1)
184
+ key = 'temperature'
185
+ wind_key = 'windSpeed'
186
+
187
+ data.each_with_index do |datum, index|
188
+ temps.push calculate_windchill(datum[key], datum[wind_key])
189
+ break if index == hours - 1 # We only want (hours) 24hrs of data.
190
+ end
191
+
192
+ differential = temps.max - temps.min
193
+
194
+ # Hmm. There's a better way.
195
+ dot_str = get_dot_str(chars, data, temps.min, differential, key)
196
+
197
+ if config.colors
198
+ dot_str = get_colored_string(data, key, dot_str, get_temp_range_colors)
199
+ end
200
+
201
+ return dot_str, temps
202
+ end
203
+
204
+ # Temp must be F.
205
+ def calculate_windchill(temp, wind)
206
+ 35.74 + (0.6215 * temp) - (35.75 * wind ** 0.16) + (0.4275 * temp * wind ** 0.16)
207
+ end
208
+
162
209
  def ansi_wind_direction_forecast(forecast)
163
- str, data = do_the_wind_direction_thing(forecast, ansi_wind_arrows)
164
- "48h wind direction #{get_speed data.first}|#{str}|#{get_speed data.last} Range: #{get_speed(data.min)} - #{get_speed(data.max)}"
210
+ str, wind_speed, wind_gust = do_the_wind_direction_thing(forecast, ansi_wind_arrows)
211
+ "48h wind direction #{get_speed wind_speed.first}|#{str}|#{get_speed wind_speed.last} Range: #{get_speed(wind_speed.min)} - #{get_speed(wind_speed.max)}, gusting to #{get_speed wind_gust.max}"
165
212
  end
166
213
 
167
214
  def ascii_wind_direction_forecast(forecast)
168
- str, data = do_the_wind_direction_thing(forecast, ascii_wind_arrows)
169
- "48h wind direction #{get_speed data.first}|#{str}|#{get_speed data.last} Range: #{get_speed(data.min)} - #{get_speed(data.max)}"
215
+ str, wind_speed, wind_gust = do_the_wind_direction_thing(forecast, ascii_wind_arrows)
216
+ "48h wind direction #{get_speed wind_speed.first}|#{str}|#{get_speed wind_speed.last} Range: #{get_speed(wind_speed.min)} - #{get_speed(wind_speed.max)}, gusting to #{get_speed wind_gust.max}"
170
217
  end
171
218
 
172
219
  def do_the_wind_direction_thing(forecast, wind_arrows, hours = 48)
@@ -174,11 +221,13 @@ module ForecastIo
174
221
  data = forecast['hourly']['data'].slice(0,hours - 1)
175
222
  str = ''
176
223
  data_points = []
224
+ gust_data = []
177
225
 
178
226
  data.each_with_index do |datum, index|
179
227
  wind_arrow_index = get_cardinal_direction_from_bearing(datum[key])
180
228
  str << wind_arrows[wind_arrow_index].to_s
181
229
  data_points.push datum['windSpeed']
230
+ gust_data.push datum['windGust']
182
231
  break if index == hours - 1 # We only want (hours) of data.
183
232
  end
184
233
 
@@ -186,7 +235,7 @@ module ForecastIo
186
235
  str = get_colored_string(data, 'windSpeed', str, get_wind_range_colors)
187
236
  end
188
237
 
189
- return str, data_points
238
+ return str, data_points, gust_data
190
239
  end
191
240
 
192
241
  def do_the_sun_thing(forecast, chars)
@@ -255,6 +304,28 @@ module ForecastIo
255
304
  "24h cloud cover |#{str}| range #{min * 100}% - #{max * 100}%"
256
305
  end
257
306
 
307
+ def do_the_fog_thing(forecast, chars)
308
+ key = 'visibility'
309
+ data_points = []
310
+ data = forecast['hourly']['data'].slice(0,23)
311
+
312
+ max = 0
313
+ min = 10
314
+
315
+ data.each do |datum|
316
+ max = datum[key] if datum[key] > max
317
+ min = datum[key] if datum[key] < min
318
+ data_points.push (10 - datum[key]).to_f # It's a visibility number, so let's inverse it to give us fog.
319
+ datum[key] = (10 - datum[key]).to_f # Mod the source data for the get_dot_str call below.
320
+ end
321
+
322
+ differential = data_points.max - data_points.min
323
+
324
+ str = get_dot_str(chars, data, 0, 10, key)
325
+
326
+ "24h fog report |#{str}| visibility #{min}mi - #{max}mi"
327
+ end
328
+
258
329
  def do_the_sunrise_thing(forecast)
259
330
  t = Time.at(fix_time(forecast['daily']['data'][0]['sunriseTime'], forecast['offset']))
260
331
  t.strftime("%H:%M:%S")
@@ -352,8 +423,9 @@ module ForecastIo
352
423
  end
353
424
 
354
425
  max = get_max_by_data_key(forecast, 'hourly', 'precipProbability')
426
+ agg = get_aggregate_by_data_key(forecast, 'hourly', 'precipIntensity')
355
427
 
356
- "48 hr #{precip_type}s |#{str}| max #{(max.to_f * 100).round}%"
428
+ "48 hr #{precip_type}s |#{str}| max #{(max.to_f * 100).round}%, #{get_accumulation agg} accumulation"
357
429
  end
358
430
 
359
431
  def do_the_daily_wind_thing(forecast)
@@ -579,5 +651,21 @@ module ForecastIo
579
651
  }
580
652
  end
581
653
  end
654
+
655
+ def do_the_uvindex_thing(forecast)
656
+ uvs = []
657
+ forecast['hourly']['data'].each do |hour|
658
+ uvs.push hour['uvIndex']
659
+ end
660
+
661
+ data = forecast['hourly']['data']
662
+ str = get_dot_str(ansi_chars, data, uvs.min, uvs.max - uvs.min, key = 'uvIndex')
663
+
664
+ if config.colors
665
+ str = get_colored_string(data, 'uvIndex', str, get_uvindex_colors)
666
+ end
667
+
668
+ "#{uvs.first} |#{str}| #{uvs.last} max: #{uvs.max}"
669
+ end
582
670
  end
583
671
  end
@@ -45,6 +45,12 @@ module ForecastIo
45
45
  response.reply location.location_name + ' ' + ansi_temp_forecast(forecast)
46
46
  end
47
47
 
48
+ def handle_irc_ansiwindchill(response)
49
+ location = geo_lookup(response.user, response.match_data[1])
50
+ forecast = get_forecast_io_results(response.user, location)
51
+ response.reply location.location_name + ' ' + ansi_windchill_forecast(forecast)
52
+ end
53
+
48
54
  def handle_irc_ieeetemp(response)
49
55
  @scale = 'k'
50
56
  location = geo_lookup(response.user, response.match_data[1])
@@ -71,15 +77,17 @@ module ForecastIo
71
77
  end
72
78
 
73
79
  def handle_irc_ansiwind(response)
74
- location = geo_lookup(response.user, response.match_data[1])
75
- forecast = get_forecast_io_results(response.user, location)
76
- response.reply location.location_name + ' ' + ansi_wind_direction_forecast(forecast)
80
+ response.reply "Sorry, darksky's api lies about wind now. Try the main interface at https://darksky.net"
81
+ # location = geo_lookup(response.user, response.match_data[1])
82
+ # forecast = get_forecast_io_results(response.user, location)
83
+ # response.reply location.location_name + ' ' + ansi_wind_direction_forecast(forecast)
77
84
  end
78
85
 
79
86
  def handle_irc_ascii_wind(response)
80
- location = geo_lookup(response.user, response.match_data[1])
81
- forecast = get_forecast_io_results(response.user, location)
82
- response.reply location.location_name + ' ' + ascii_wind_direction_forecast(forecast)
87
+ response.reply "Sorry, darksky's api lies about wind now. Try the main interface at https://darksky.net"
88
+ # location = geo_lookup(response.user, response.match_data[1])
89
+ # forecast = get_forecast_io_results(response.user, location)
90
+ # response.reply location.location_name + ' ' + ascii_wind_direction_forecast(forecast)
83
91
  end
84
92
 
85
93
  def handle_irc_alerts(response)
@@ -119,6 +127,18 @@ module ForecastIo
119
127
  response.reply location.location_name + ' ' + do_the_cloud_thing(forecast, ascii_chars)
120
128
  end
121
129
 
130
+ def handle_irc_ansifog(response)
131
+ location = geo_lookup(response.user, response.match_data[1])
132
+ forecast = get_forecast_io_results(response.user, location)
133
+ response.reply location.location_name + ' ' + do_the_fog_thing(forecast, ansi_chars)
134
+ end
135
+
136
+ def handle_irc_asciifog(response)
137
+ location = geo_lookup(response.user, response.match_data[1])
138
+ forecast = get_forecast_io_results(response.user, location)
139
+ response.reply location.location_name + ' ' + do_the_fog_thing(forecast, ascii_chars)
140
+ end
141
+
122
142
  def handle_irc_seven_day(response)
123
143
  location = geo_lookup(response.user, response.match_data[1])
124
144
  forecast = get_forecast_io_results(response.user, location)
@@ -138,9 +158,10 @@ module ForecastIo
138
158
  end
139
159
 
140
160
  def handle_irc_daily_wind(response)
141
- location = geo_lookup(response.user, response.match_data[1])
142
- forecast = get_forecast_io_results(response.user, location)
143
- response.reply location.location_name + ' ' + do_the_daily_wind_thing(forecast)
161
+ response.reply "Sorry, darksky's api lies about wind now. Try the main interface at https://darksky.net"
162
+ # location = geo_lookup(response.user, response.match_data[1])
163
+ # forecast = get_forecast_io_results(response.user, location)
164
+ # response.reply location.location_name + ' ' + do_the_daily_wind_thing(forecast)
144
165
  end
145
166
 
146
167
  def handle_irc_daily_humidity(response)
@@ -235,5 +256,13 @@ module ForecastIo
235
256
  windows_data = do_the_windows_data_thing(forecast)
236
257
  response.write windows_data.to_json
237
258
  end
259
+
260
+ def handle_irc_uvindex(response)
261
+ location = geo_lookup(response.user, response.match_data[1])
262
+ forecast = get_forecast_io_results(response.user, location)
263
+ str = do_the_uvindex_thing(forecast)
264
+ response.reply "UV Index for #{location.location_name} #{str} [48h forecast]"
265
+ end
266
+
238
267
  end
239
268
  end
@@ -15,6 +15,7 @@ module Lita
15
15
  config :colors
16
16
  config :snowflake, default: '❄'
17
17
  config :default_location, default: 'Portland, OR'
18
+ config :geocoder_key
18
19
 
19
20
  include ::ForecastIo::Constants
20
21
  include ::ForecastIo::IrcHandlers
@@ -82,6 +83,15 @@ module Lita
82
83
  route(/^windows\s+(.+)/i, :handle_irc_windows, command: true,
83
84
  help: { '!windows' => 'Tell me when to close my windows as it\'s warmer outside than in.'})
84
85
 
86
+ # SUN
87
+ route(/^uv$/i, :handle_irc_uvindex, command: true)
88
+ route(/^uv\s+(.+)$/i, :handle_irc_uvindex, command: true)
89
+ route(/^uvindex$/i, :handle_irc_uvindex, command: true)
90
+ route(/^uvindex\s+(.*)$/i, :handle_irc_uvindex, command: true)
91
+ route(/^ansiuvindex\s*(.*)$/i, :handle_irc_uvindex, command: true)
92
+ route(/^ansiuv\s*(.*)$/i, :handle_irc_uvindex, command: true,
93
+ help: { '!ansiuv' => 'Display the UV index forecast.' })
94
+
85
95
  # State Commands
86
96
  route(/^set scale (c|f|k)/i, :handle_irc_set_scale, command: true,
87
97
  help: { '!set scale [c|f|k]' => 'Set the scale to your chosen degrees.'})
@@ -148,6 +158,9 @@ module Lita
148
158
  route(/^ansiwind\s*$/i, :handle_irc_ansiwind, command: true)
149
159
  route(/^ansiwind\s+(.+)/i, :handle_irc_ansiwind, command: true,
150
160
  help: { '!ansiwind [location]' => '24h wind speed/direction report for [location].'})
161
+ route(/^ansiwindchill\s*$/i, :handle_irc_ansiwindchill, command: true)
162
+ route(/^ansiwindchill\s+(.+)/i, :handle_irc_ansiwindchill, command: true,
163
+ help: { '!ansiwindchill [location]' => '24h windchill temp report for [location].'})
151
164
  route(/^asciiwind\s*$/i, :handle_irc_ascii_wind, command: true)
152
165
  route(/^asciiwind\s+(.+)/i, :handle_irc_ascii_wind, command: true,
153
166
  help: { '!asciiwind [location]' => '24h wind speed/direction report for [location], ascii style.'})
@@ -162,6 +175,12 @@ module Lita
162
175
  route(/^ansiclouds*\s*$/i, :handle_irc_ansicloud, command: true)
163
176
  route(/^ansiclouds*\s+(.+)/i, :handle_irc_ansicloud, command: true,
164
177
  help: { '!ansicloud [location]' => '24h cloud cover report for [location].'})
178
+ route(/^asciifog*\s*$/i, :handle_irc_asciifog, command: true)
179
+ route(/^asciifog*\s+(.+)/i, :handle_irc_asciifog, command: true,
180
+ help: { '!ansicloud [location]' => '24h fog/visibility report for [location].'})
181
+ route(/^ansifog*\s*$/i, :handle_irc_ansifog, command: true)
182
+ route(/^ansifog*\s+(.+)/i, :handle_irc_ansifog, command: true,
183
+ help: { '!ansicloud [location]' => '24h fog/visibility report for [location].'})
165
184
 
166
185
  # oooOOOoooo
167
186
  route(/^ansiozone\s*$/i, :handle_irc_ansiozone, command: true)
@@ -45,8 +45,11 @@ module ForecastIo
45
45
 
46
46
  # Geographical stuffs
47
47
  # Now with moar caching!
48
- def optimistic_geo_wrapper(query)
48
+ def optimistic_geo_wrapper(query, geocoder_key)
49
49
  Lita.logger.debug "Optimistically geo wrapping #{query}!"
50
+ ::Geocoder.configure(
51
+ :api_key => geocoder_key
52
+ )
50
53
  geocoded = nil
51
54
  result = ::Geocoder.search(query)
52
55
  Lita.logger.debug "Geocoder result: '#{result.inspect}'"
@@ -59,36 +62,113 @@ module ForecastIo
59
62
  # Perform a geocoder lookup based on a) the query or b) the user's serialized state.
60
63
  # If neither of those exist, default to config location.
61
64
  def geo_lookup(user, query, persist = true)
62
- Lita.logger.debug "Performing geolookup for '#{user.name}' for '#{query}'"
65
+ Lita.logger.debug "Performing geolookup for '#{user}' for '#{query}'"
66
+
67
+ geocoded = nil
63
68
 
64
69
  if query.nil? or query.empty?
65
- Lita.logger.debug "No query specified, pulling from redis #{REDIS_KEY}, #{user.name}"
66
- serialized_geocoded = redis.hget(REDIS_KEY, user.name)
70
+ Lita.logger.debug "No query specified, pulling from redis '#{REDIS_KEY}', '#{user}'"
71
+ serialized_geocoded = redis.hget(REDIS_KEY, user)
67
72
  unless serialized_geocoded == 'null' or serialized_geocoded.nil?
68
- geocoded = JSON.parse(serialized_geocoded)
73
+ if serialized_geocoded[/^http/]
74
+ query = serialized_geocoded
75
+ else
76
+ geocoded = JSON.parse(serialized_geocoded)
77
+ end
78
+ Lita.logger.debug "Cached location: #{geocoded.inspect}"
69
79
  end
70
- Lita.logger.debug "Cached location: #{geocoded.inspect}"
71
80
  end
72
81
 
73
82
  query = (query.nil?)? config.default_location : query
74
83
  Lita.logger.debug "q & g #{query.inspect} #{geocoded.inspect}"
75
84
 
76
- unless geocoded
77
- Lita.logger.debug "Redis hget failed, performing lookup for #{query}"
78
- geocoded = optimistic_geo_wrapper query
79
- Lita.logger.debug "Geolocation found. '#{geocoded.inspect}' failed, performing lookup"
85
+ if query[/^http/] or (!geocoded.nil? and geocoded.key? 'geo') # For now this is aaronpk's loc
86
+ Lita.logger.debug "Getting location from #{query}"
87
+ resp = JSON.parse(RestClient.get query)
88
+
89
+ locality = ''
90
+ if resp['geo']
91
+ locality = resp['geo']['locality']
92
+ end
93
+
94
+ geocoded = optimistic_geo_wrapper locality, config.geocoder_key
95
+
96
+ # loc = Location.new(
97
+ # locality,
98
+ # resp['location']['latitude'],
99
+ # resp['location']['longitude']
100
+ # )
101
+
80
102
  if persist
81
- redis.hset(REDIS_KEY, user.name, geocoded.to_json)
103
+ redis.hset(REDIS_KEY, user, query)
104
+ end
105
+
106
+ else
107
+
108
+ unless geocoded
109
+ # uri = "https://atlas.p3k.io/api/geocode?input=#{URI.escape query}"
110
+ # Lita.logger.debug "Redis hget failed, performing lookup for #{query} on #{uri}"
111
+ geocoded = optimistic_geo_wrapper query, config.geocoder_key
112
+ # Catch network errors here
113
+ # begin
114
+ # geocoded = JSON.parse RestClient.get(uri)
115
+ # rescue RuntimeError => e
116
+ # puts "x"
117
+ # end
118
+
119
+ Lita.logger.debug "Geolocation found. '#{geocoded.inspect}' failed, performing lookup"
120
+ if persist
121
+ redis.hset(REDIS_KEY, user, geocoded.to_json)
122
+ end
82
123
  end
124
+
125
+ # {"latitude": 45.51179,
126
+ # "longitude": -122.67563,
127
+ # "locality": "Portland",
128
+ # "region": "Oregon",
129
+ # "country": "USA",
130
+ # "best_name": "Portland",
131
+ # "full_name": "Portland, Oregon, USA",
132
+ # "postal-code": "97201",
133
+ # "timezone": "America\/Los_Angeles",
134
+ # "offset": "-07:00",
135
+ # "seconds": -25200,
136
+ # "localtime": "2018-08-09T08:05:43-07:00"}
137
+
138
+ # loc = Location.new(
139
+ # geocoded['best_name'],
140
+ # geocoded['latitude'],
141
+ # geocoded['longitude']
142
+ # )
143
+ # loc = Location.new(
144
+ # geocoded['formatted_address'],
145
+ # geocoded['geometry']['location']['lat'],
146
+ # geocoded['geometry']['location']['lng']
147
+ # )
148
+
83
149
  end
84
150
 
85
- Lita.logger.debug "geocoded: '#{geocoded}'"
86
- loc = Location.new(
87
- "#{geocoded['address']['city']}, #{geocoded['address']['state']}",
88
- geocoded['lat'],
89
- geocoded['lon']
90
- )
151
+ Lita.logger.debug "best_name: #{geocoded['best_name']}"
152
+ Lita.logger.debug "display_name: #{geocoded['display_name']}"
153
+ Lita.logger.debug "formatted_address: #{geocoded['formatted_address']}"
154
+ if geocoded['best_name']
155
+ loc = Location.new(
156
+ geocoded['best_name'],
157
+ geocoded['latitude'],
158
+ geocoded['longitude'])
159
+ elsif geocoded['lon']
160
+ loc = Location.new(
161
+ "#{geocoded['address']['city']}, #{geocoded['address']['state']}",
162
+ geocoded['lat'],
163
+ geocoded['lon'])
164
+ else
165
+ loc = Location.new(
166
+ geocoded['formatted_address'],
167
+ geocoded['geometry']['location']['lat'],
168
+ geocoded['geometry']['location']['lng'])
169
+ end
91
170
 
171
+ Lita.logger.debug "geocoded: '#{geocoded}'"
92
172
  Lita.logger.debug "loc: '#{loc}'"
93
173
 
94
174
  loc
@@ -150,6 +230,8 @@ module ForecastIo
150
230
  uri += ",#{time}"
151
231
  end
152
232
 
233
+ uri += "?units=si"
234
+
153
235
  Lita.logger.debug "Requesting forcast data from: #{uri}"
154
236
  set_scale(user)
155
237
  gimme_some_weather uri
@@ -315,6 +397,14 @@ module ForecastIo
315
397
  end
316
398
  end
317
399
 
400
+ def get_accumulation(accum_mm)
401
+ if @scale == 'c' or @scale == 'k'
402
+ accum_mm.round(0).to_s + 'mm'
403
+ else
404
+ inches_from_mm(accum_mm).to_s + 'in'
405
+ end
406
+ end
407
+
318
408
  def get_humidity(humidity_decimal)
319
409
  (humidity_decimal * 100).round(0).to_s + '%'
320
410
  end
@@ -327,6 +417,10 @@ module ForecastIo
327
417
  ((degrees_f.to_f + 459.67) * 5/9).round(2)
328
418
  end
329
419
 
420
+ def inches_from_mm(dist_mm)
421
+ (dist_mm * 0.0393701).round(1)
422
+ end
423
+
330
424
  def kilometers(speed_imperial)
331
425
  (speed_imperial * 1.6).round(2)
332
426
  end
@@ -1,7 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-onewheel-forecast-io'
3
- spec.version = '1.6.7
4
- '
3
+ spec.version = '1.13.1'
5
4
  spec.authors = ['Andrew Kreps']
6
5
  spec.email = ['andrew.kreps@gmail.com']
7
6
  spec.description = <<-EOS
@@ -31,7 +30,7 @@ EOS
31
30
  spec.add_development_dependency 'coveralls', '~> 0.8'
32
31
 
33
32
  spec.add_runtime_dependency 'rest-client', '~> 2'
34
- spec.add_runtime_dependency 'geocoder', '~> 1.2'
33
+ spec.add_runtime_dependency 'geocoder', '~> 1.5'
35
34
  spec.add_runtime_dependency 'multi_json', '~> 1.7'
36
35
  spec.add_runtime_dependency 'magic-eightball', '~> 0.0'
37
36
  spec.add_runtime_dependency 'tzinfo', '~> 1.2'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-onewheel-forecast-io
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.7
4
+ version: 1.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kreps
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-26 00:00:00.000000000 Z
11
+ date: 2020-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '1.2'
131
+ version: '1.5'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '1.2'
138
+ version: '1.5'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: multi_json
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -234,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
234
  - !ruby/object:Gem::Version
235
235
  version: '0'
236
236
  requirements: []
237
- rubygems_version: 3.0.3
237
+ rubygems_version: 3.1.2
238
238
  signing_key:
239
239
  specification_version: 4
240
240
  summary: A text-based interactive query engine for http://forecast.io's api.