lita-onewheel-aqi 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -2
- data/README.md +36 -0
- data/lib/lita/handlers/onewheel_aqi.rb +80 -22
- data/lita-onewheel-aqi.gemspec +1 -1
- data/spec/lita/handlers/onewheel_aqi_spec.rb +8 -1
- metadata +2 -2
- data/README.rst +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13823ee556bbd908e18efa0011f9d44e90c383e6
|
4
|
+
data.tar.gz: e21fcd064eb874cda6684ee11135cf808525af38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66f020d2df9500bbe13e528ff6ab7985416a81a8c28068934a591fa14d1f8e40c70ffb6626bd7236ad55946bf8f00dd6891d8a17a96095a204cf661ef40d5276
|
7
|
+
data.tar.gz: 7dabe75aa72ab43f7848e365fbee2bc37069935073919d30657f19cde9fcd692dd1d3c05abee65c76795bae1453d7856aa6f887efdcf3fa69febf5a47ae1fb7a
|
data/.travis.yml
CHANGED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# lita-onewheel-aqi
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/onewheelskyward/lita-onewheel-aqi.svg?branch=master)](https://travis-ci.org/onewheelskyward/lita-onewheel-aqi)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/onewheelskyward/lita-onewheel-aqi/badge.svg?branch=master)](https://coveralls.io/github/onewheelskyward/lita-onewheel-aqi?branch=master)
|
5
|
+
|
6
|
+
I built this on a plane on day where wildfire smoke had caused Portland, OR's air quality to be worse than Hong Kong's.
|
7
|
+
The next year, I upgraded it to use a newer, better API.
|
8
|
+
|
9
|
+
http://airnowapi.org/aq101
|
10
|
+
|
11
|
+
http://aqicn.org/city/usa/oregon/portland
|
12
|
+
|
13
|
+
# Installation
|
14
|
+
|
15
|
+
Add lita-onewheel-aqi to your Lita instance's Gemfile:
|
16
|
+
|
17
|
+
`gem 'lita-onewheel-aqi'`
|
18
|
+
|
19
|
+
# Configuration
|
20
|
+
|
21
|
+
Add your API key to your lita_config.rb:
|
22
|
+
|
23
|
+
`config.handlers.onewheel_aqi.api_key`
|
24
|
+
|
25
|
+
It can be procured here: http://aqicn.org/api/
|
26
|
+
|
27
|
+
If you're using this in slack, turn off the IRC color codes by using:
|
28
|
+
|
29
|
+
`config.handlers.onewheel_aqi.colors = false`
|
30
|
+
|
31
|
+
# Usage
|
32
|
+
|
33
|
+
bot: aqi Portland, OR
|
34
|
+
|
35
|
+
^^ should return your PM2.5 number.
|
36
|
+
|
@@ -8,10 +8,21 @@ module Lita
|
|
8
8
|
config :distance
|
9
9
|
config :colors, default: true
|
10
10
|
|
11
|
-
route /^aqi(.*)$/i,
|
11
|
+
route /^aqi\s+(.*)$/i,
|
12
12
|
:get_aqi,
|
13
13
|
command: true,
|
14
14
|
help: { '!aqi [location]' => 'Gives you available data for air quality (PM2.5) forecast and latest observation.' }
|
15
|
+
route /^aqi$/i,
|
16
|
+
:get_aqi,
|
17
|
+
command: true
|
18
|
+
route /^aqideets\s*(.*)$/i,
|
19
|
+
:get_aqi_deets,
|
20
|
+
command: true,
|
21
|
+
help: { '!aqideets [location]' => 'Gives you moar datas.' }
|
22
|
+
route /^aqidetails\s*(.*)$/i,
|
23
|
+
:get_aqi_deets,
|
24
|
+
command: true,
|
25
|
+
help: { '!aqideets [location]' => 'Gives you moar datas.' }
|
15
26
|
|
16
27
|
# IRC colors.
|
17
28
|
def colors
|
@@ -43,48 +54,88 @@ module Lita
|
|
43
54
|
301..500 => :pink }
|
44
55
|
end
|
45
56
|
|
46
|
-
def
|
47
|
-
location = response.matches[0]
|
48
|
-
|
49
|
-
|
57
|
+
def get_location(response)
|
58
|
+
location = if response.matches[0].to_s.casecmp('aqi').zero?
|
59
|
+
''
|
60
|
+
else
|
61
|
+
response.matches[0][0]
|
62
|
+
end
|
63
|
+
|
64
|
+
puts "get_location: '#{location}'"
|
65
|
+
location = 'Portland, OR' if location.nil? || location.empty?
|
50
66
|
|
51
67
|
loc = geo_lookup(location)
|
52
68
|
puts loc.inspect
|
69
|
+
loc
|
70
|
+
end
|
53
71
|
|
54
|
-
|
55
|
-
uri = "http://api.waqi.info/feed/geo:#{loc[:lat]};#{loc[:lng]}/?token=#{api_key}"
|
72
|
+
def get_observed_aqi(loc)
|
73
|
+
uri = "http://api.waqi.info/feed/geo:#{loc[:lat]};#{loc[:lng]}/?token=#{config.api_key}"
|
56
74
|
Lita.logger.debug "Getting aqi from #{uri}"
|
57
|
-
# forecast_response = RestClient.get(uri)
|
58
|
-
# forecasted_aqi = JSON.parse(forecast_response)
|
59
|
-
# Lita.logger.debug 'Forecast response: ' + forecasted_aqi.inspect
|
60
75
|
|
61
76
|
observed_response = RestClient.get(uri)
|
62
77
|
observed_aqi = JSON.parse(observed_response)
|
63
78
|
Lita.logger.debug 'Observed response: ' + observed_aqi.inspect
|
79
|
+
observed_aqi
|
80
|
+
end
|
64
81
|
|
65
|
-
|
82
|
+
def get_aqi(response)
|
83
|
+
loc = get_location(response)
|
84
|
+
aqi = get_observed_aqi(loc)
|
66
85
|
|
67
86
|
reply = "AQI for #{loc[:name]}, "
|
68
|
-
# unless forecasted_aqi == []
|
69
|
-
# reply += "Forecasted: #{(forecasted_aqi['ActionDay'] == 'true')? 'Action Day! ' : ''}#{forecasted_aqi['AQI']} #{forecasted_aqi['Category']['Name']} "
|
70
|
-
# end
|
71
87
|
|
72
|
-
|
73
|
-
|
74
|
-
|
88
|
+
if aqi['data']['iaqi']['pm10']
|
89
|
+
reply += 'pm10: ' + color_str(aqi['data']['iaqi']['pm10']['v'].to_s) + ' '
|
90
|
+
end
|
91
|
+
if aqi['data']['iaqi']['pm25']
|
92
|
+
reply += 'pm25: ' + color_str(aqi['data']['iaqi']['pm25']['v'].to_s) + ' '
|
75
93
|
end
|
76
94
|
|
77
|
-
|
78
|
-
|
95
|
+
banner_str = "(#{aqi['data']['city']['url']})"
|
96
|
+
banner_str = "\x03#{colors[:grey]}#{banner_str}\x03" if config.colors
|
97
|
+
|
98
|
+
reply += banner_str
|
99
|
+
|
100
|
+
response.reply reply
|
101
|
+
end
|
102
|
+
|
103
|
+
def get_aqi_deets(response)
|
104
|
+
loc = get_location(response)
|
105
|
+
aqi = get_observed_aqi(loc)
|
106
|
+
|
107
|
+
reply = "AQI for #{loc[:name]}, "
|
108
|
+
|
109
|
+
banner_str = "(#{aqi['data']['city']['url']})"
|
110
|
+
banner_str = "\x03#{colors[:grey]}#{banner_str}\x03" if config.colors
|
111
|
+
|
112
|
+
if aqi['data']['iaqi']['co']
|
113
|
+
reply += 'co: ' + aqi['data']['iaqi']['co']['v'].to_s + ' '
|
114
|
+
end
|
115
|
+
if aqi['data']['iaqi']['h']
|
116
|
+
reply += 'humidity: ' + aqi['data']['iaqi']['h']['v'].to_s + '% '
|
79
117
|
end
|
118
|
+
if aqi['data']['iaqi']['p']
|
119
|
+
reply += 'pressure: ' + aqi['data']['iaqi']['p']['v'].to_s + 'mb '
|
120
|
+
end
|
121
|
+
if aqi['data']['iaqi']['pm10']
|
122
|
+
reply += 'pm10: ' + color_str(aqi['data']['iaqi']['pm10']['v'].to_s) + ' '
|
123
|
+
end
|
124
|
+
if aqi['data']['iaqi']['pm25']
|
125
|
+
reply += 'pm25: ' + color_str(aqi['data']['iaqi']['pm25']['v'].to_s) + ' '
|
126
|
+
end
|
127
|
+
if aqi['data']['iaqi']['t']
|
128
|
+
reply += 'temp: ' + aqi['data']['iaqi']['t']['v'].to_s + 'C '
|
129
|
+
end
|
130
|
+
|
131
|
+
reply += banner_str
|
80
132
|
response.reply reply
|
81
133
|
end
|
82
134
|
|
83
135
|
def color_str(str)
|
84
|
-
|
85
136
|
if config.colors
|
86
137
|
aqi_range_colors.keys.each do |color_key|
|
87
|
-
if color_key.cover? str.to_i
|
138
|
+
if color_key.cover? str.to_i # Super secred cover sauce
|
88
139
|
color = colors[aqi_range_colors[color_key]]
|
89
140
|
str = "\x03#{color}#{str}\x03"
|
90
141
|
end
|
@@ -95,7 +146,14 @@ module Lita
|
|
95
146
|
end
|
96
147
|
|
97
148
|
def extract_pmtwofive(aqi)
|
98
|
-
aqi
|
149
|
+
Lita.logger.debug "extract_pmtwofive with #{aqi}"
|
150
|
+
pm25 = ''
|
151
|
+
pm25 = if aqi['data']['iaqi']['pm25']
|
152
|
+
aqi['data']['iaqi']['pm25']['v']
|
153
|
+
else
|
154
|
+
"No PM2.5 data for #{aqi['data']['city']['name']}"
|
155
|
+
end
|
156
|
+
pm25
|
99
157
|
end
|
100
158
|
|
101
159
|
# Geographical stuffs
|
data/lita-onewheel-aqi.gemspec
CHANGED
@@ -2,6 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Lita::Handlers::OnewheelAqi, lita_handler: true do
|
4
4
|
it { is_expected.to route_command('aqi') }
|
5
|
+
it { is_expected.to route_command('aqidetails') }
|
6
|
+
it { is_expected.to route_command('aqideets') }
|
5
7
|
|
6
8
|
before do
|
7
9
|
mock = File.open('spec/fixtures/Output.json').read
|
@@ -29,6 +31,11 @@ describe Lita::Handlers::OnewheelAqi, lita_handler: true do
|
|
29
31
|
|
30
32
|
it 'queries the aqi' do
|
31
33
|
send_command 'aqi'
|
32
|
-
expect(replies.last).to include("AQI for Portland, OR, USA,
|
34
|
+
expect(replies.last).to include("AQI for Portland, OR, USA, pm10: \u00030340\u0003 pm25: \u00030876\u0003 \u000314(http://aqicn.org/city/usa/oregon/government-camp-multorpor-visibility/)\u0003")
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'queries the aqideets' do
|
38
|
+
send_command 'aqideets'
|
39
|
+
expect(replies.last).to eq("AQI for Portland, OR, USA, humidity: 11% pressure: 1014mb pm10: \u00030340\u0003 pm25: \u00030876\u0003 temp: 34.65C \u000314(http://aqicn.org/city/usa/oregon/government-camp-multorpor-visibility/)\u0003")
|
33
40
|
end
|
34
41
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-onewheel-aqi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kreps
|
@@ -146,7 +146,7 @@ files:
|
|
146
146
|
- ".gitignore"
|
147
147
|
- ".travis.yml"
|
148
148
|
- Gemfile
|
149
|
-
- README.
|
149
|
+
- README.md
|
150
150
|
- Rakefile
|
151
151
|
- lib/lita-onewheel-aqi.rb
|
152
152
|
- lib/lita/handlers/onewheel_aqi.rb
|
data/README.rst
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
lita-onewheel-aqi
|
2
|
-
=================
|
3
|
-
|
4
|
-
.. image:: https://coveralls.io/repos/onewheelskyward/lita-onewheel-aqi/badge.svg?branch=master&service=github :target: https://coveralls.io/github/onewheelskyward/lita-onewheel-aqi?branch=master
|
5
|
-
.. image:: https://travis-ci.org/onewheelskyward/lita-onewheel-aqi.svg?branch=master :target: https://travis-ci.org/onewheelskyward/lita-onewheel-aqi
|
6
|
-
|
7
|
-
I built this on a plane on day where wildfire smoke had caused Portland, OR's air quality to be worse than Hong Kong's.
|
8
|
-
The data is a little spotty, but it worked good enough for an hour at the stick.
|
9
|
-
|
10
|
-
http://airnowapi.org/aq101
|
11
|
-
|
12
|
-
http://airnowapi.org/webservices
|
13
|
-
|
14
|
-
http://airnowapi.org/forecastsbylatlon/docs
|
15
|
-
|
16
|
-
Installation
|
17
|
-
============
|
18
|
-
Add lita-onewheel-aqi to your Lita instance's Gemfile:
|
19
|
-
|
20
|
-
``gem 'lita-onewheel-aqi'``
|
21
|
-
|
22
|
-
Configuration
|
23
|
-
=============
|
24
|
-
|
25
|
-
Add your API key to your lita_config.rb:
|
26
|
-
|
27
|
-
``config.handlers.onewheel_aqi.api_key``
|
28
|
-
|
29
|
-
It can be procured here: http://airnowapi.org/account/request/
|
30
|
-
|
31
|
-
Usage
|
32
|
-
=====
|
33
|
-
|
34
|
-
bot: aqi Portland, OR
|
35
|
-
|
36
|
-
^^ should return your PM2.5 number.
|
37
|
-
|