lita-onewheel-aqi 2.0.12 → 2.1.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 +4 -4
- data/lib/lita/handlers/onewheel_aqi.rb +41 -21
- data/lita-onewheel-aqi.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18a828b5b2257a136b9266c7a8156bb528980302
|
4
|
+
data.tar.gz: b624f8d89a548f2114fb37f1815024cfb1ed3d76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7376eaeb124011ddaf21330d44aa656bd789cfdb3c6f68962d07c9689ae6b4623ba3a2d28b2193f61680d82784bbdd1013078d9c9eb89f8176aef56824db6d83
|
7
|
+
data.tar.gz: 49b4cb8dfcd24c89acd95802fe1d6629f5699758879abe981cfb14aa3827c07d424e9427f83fee9c079a0fcd2db26f97b353d00b0612b9fc471cc0f3b275852d
|
@@ -8,6 +8,8 @@ module Lita
|
|
8
8
|
config :distance
|
9
9
|
config :mode, default: :irc
|
10
10
|
|
11
|
+
REDIS_KEY = 'onewheel-aqi'
|
12
|
+
|
11
13
|
route /^aqi\s+(.*)$/i,
|
12
14
|
:get_aqi,
|
13
15
|
command: true,
|
@@ -81,18 +83,47 @@ module Lita
|
|
81
83
|
301..500 => '🚫☣🚫' }
|
82
84
|
end
|
83
85
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
86
|
+
# Perform a geocoder lookup based on a) the query or b) the user's serialized state.
|
87
|
+
# If neither of those exist, default to config location.
|
88
|
+
def get_location(response, persist = true)
|
89
|
+
user = response.user
|
90
|
+
query = nil
|
91
|
+
if response.matches[0].is_a?(Array) and response.matches[0].empty?
|
92
|
+
query = response.matches[0][0]
|
93
|
+
end
|
94
|
+
|
95
|
+
Lita.logger.debug "Performing geolookup for '#{user.name}' for '#{query}'"
|
96
|
+
|
97
|
+
if query.nil? or query.empty?
|
98
|
+
Lita.logger.debug "No query specified, pulling from redis #{REDIS_KEY}, #{user.name}"
|
99
|
+
serialized_geocoded = redis.hget(REDIS_KEY, user.name)
|
100
|
+
unless serialized_geocoded == 'null' or serialized_geocoded.nil?
|
101
|
+
geocoded = JSON.parse(serialized_geocoded)
|
102
|
+
end
|
103
|
+
Lita.logger.debug "Cached location: #{geocoded.inspect}"
|
104
|
+
end
|
105
|
+
|
106
|
+
query = (query.nil?)? 'Portland, OR' : query
|
107
|
+
Lita.logger.debug "q & g #{query.inspect} #{geocoded.inspect}"
|
108
|
+
|
109
|
+
unless geocoded
|
110
|
+
Lita.logger.debug "Redis hget failed, performing lookup for #{query}"
|
111
|
+
geocoded = optimistic_geo_wrapper query
|
112
|
+
Lita.logger.debug "Geolocation found. '#{geocoded.inspect}' failed, performing lookup"
|
113
|
+
if persist
|
114
|
+
redis.hset(REDIS_KEY, user.name, geocoded.to_json)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
Lita.logger.debug "geocoded: '#{geocoded}'"
|
119
|
+
loc = {
|
120
|
+
name: geocoded['formatted_address'],
|
121
|
+
lat: geocoded['geometry']['location']['lat'],
|
122
|
+
lng: geocoded['geometry']['location']['lng']
|
123
|
+
}
|
90
124
|
|
91
|
-
|
92
|
-
location = 'Portland, OR' if location.nil? || location.empty?
|
125
|
+
Lita.logger.debug "loc: '#{loc}'"
|
93
126
|
|
94
|
-
loc = geo_lookup(location)
|
95
|
-
puts loc.inspect
|
96
127
|
loc
|
97
128
|
end
|
98
129
|
|
@@ -220,17 +251,6 @@ module Lita
|
|
220
251
|
geocoded
|
221
252
|
end
|
222
253
|
|
223
|
-
def geo_lookup(query)
|
224
|
-
puts "Location lookup #{query.inspect}"
|
225
|
-
geocoded = optimistic_geo_wrapper query
|
226
|
-
|
227
|
-
query = 'Portland, OR' if (query.nil? || query.empty?) && geocoded.nil?
|
228
|
-
|
229
|
-
{ name: geocoded['formatted_address'],
|
230
|
-
lat: geocoded['geometry']['location']['lat'],
|
231
|
-
lng: geocoded['geometry']['location']['lng'] }
|
232
|
-
end
|
233
|
-
|
234
254
|
# Particulate Matter 2.5 to micrograms per cubic meter
|
235
255
|
def pm25_to_ugm3(pm25)
|
236
256
|
ranges = {
|
data/lita-onewheel-aqi.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-onewheel-aqi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kreps
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|