lita-onewheel-aqi 1.1.1 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1718ac9cefb5363670b2ae7372a4c724cbd4a775
4
- data.tar.gz: b4c06144a240f7e331cffdee4c584566466954b4
3
+ metadata.gz: 13823ee556bbd908e18efa0011f9d44e90c383e6
4
+ data.tar.gz: e21fcd064eb874cda6684ee11135cf808525af38
5
5
  SHA512:
6
- metadata.gz: 0a0ab305267ae4221469f86efaf805203316955c05fd6df66f87e869f39ad457f23876b58dad71959b554ef9e74064824e853249a2b6468caccd11249c1ae16b
7
- data.tar.gz: 4da4e27f04a59a770cfa99165831893e1770c4d86fe892619f1fb64aeb1b966c393c9d71f362c1d7c7a6f4fe9e8187189ac2796959d907875600449240795d4b
6
+ metadata.gz: 66f020d2df9500bbe13e528ff6ab7985416a81a8c28068934a591fa14d1f8e40c70ffb6626bd7236ad55946bf8f00dd6891d8a17a96095a204cf661ef40d5276
7
+ data.tar.gz: 7dabe75aa72ab43f7848e365fbee2bc37069935073919d30657f19cde9fcd692dd1d3c05abee65c76795bae1453d7856aa6f887efdcf3fa69febf5a47ae1fb7a
data/.travis.yml CHANGED
@@ -1,7 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.4
4
- - 2.3.0
3
+ - 2.3.4
5
4
  script: bundle exec rake
6
5
  before_install:
7
6
  - gem update --system
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 get_aqi(response)
47
- location = response.matches[0][0].to_s.strip
48
- puts "'#{location}'"
49
- location = 'Portland, OR' if location.empty?
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
- api_key = 'd4d71949d26fcaa48783808fdba32fbdc8d367eb'
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
- observed_pm25 = extract_pmtwofive(observed_aqi)
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
- banner_str = "(#{observed_aqi['data']['city']['url']})"
73
- if config.colors
74
- banner_str = "\x03#{colors[:grey]}#{banner_str}\x03"
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
- unless observed_aqi == []
78
- reply += "Observed PM25: #{color_str(observed_pm25)} #{banner_str}"
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 # Super secred cover sauce
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['data']['iaqi']['pm25']['v']
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-onewheel-aqi'
3
- spec.version = '1.1.1'
3
+ spec.version = '1.2.0'
4
4
  spec.authors = ['Andrew Kreps']
5
5
  spec.email = ['andrew.kreps@gmail.com']
6
6
  spec.description = 'AQI data retrieval bot'
@@ -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, Observed PM25: \u00030876\u0003 \u000314(http://aqicn.org/city/usa/oregon/government-camp-multorpor-visibility/)\u0003")
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.1.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.rst
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
-