barometer-cli 0.0.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 +15 -0
- data/.gitignore +16 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +1 -0
- data/barometer-cli.gemspec +25 -0
- data/bin/barometer +424 -0
- data/lib/barometer/cli.rb +7 -0
- data/lib/barometer/cli/version.rb +5 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NWZiZWIxNGI4NTY2MjEzOTc4YTQyNTBiODllNjI4ZmRmYzkyYjRhOA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDczZjQyNTBkNGI5NmY2MzE3M2IxODNhMjY4NTFjMjI5ZTBhNWYwMw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODhlOWNhYzQzMjJiZjJiYzI4MWM3ODVjOWMxOWRiOTRjZmMzYTI3ODFmNmJk
|
10
|
+
Y2JjNjU0ODEyM2VlZjJjOWU2ZTQxZDczZWJkZWI4MjM4NjNhZjQ4YWIzNWQx
|
11
|
+
NDkxYTZhZGQyYjQ1ZmVjYjc3ZWI3YmVjNjRkMGY3MDYyYzM1MjQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZjJjZWNlZjFjYWY4ZGU4MTBlMGE5MjUwZjdmMTZjNmMyNDhiNmU5MTk2Mjlm
|
14
|
+
N2NiNmI2NjUzMjU4OThiZTFmNDUzMzIxYWI2NzRjNDdiZjgzMzEwOTFkN2Nl
|
15
|
+
Y2U1NTRlYjI1NDRlMTdlNWViNTAzMmQzOWFlNThmZTM2NDBiYTE=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Mark
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Barometer CLI
|
2
|
+
|
3
|
+
Barometer via the command line. Extracted from the
|
4
|
+
[Barometer gem](https://github.com/attack/barometer)
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'barometer-cli'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install barometer-cli
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
```sh
|
23
|
+
% barometer berlin
|
24
|
+
```
|
25
|
+
|
26
|
+
This will output the weather information for the given query.
|
27
|
+
See the help for more command line information.
|
28
|
+
|
29
|
+
```sh
|
30
|
+
% barometer -h
|
31
|
+
```
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
40
|
+
|
41
|
+
## Copyright
|
42
|
+
|
43
|
+
Copyright (c) 2009-2013 Mark G. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'barometer/cli/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'barometer-cli'
|
8
|
+
spec.version = Barometer::Cli::VERSION
|
9
|
+
spec.authors = ['Mark G']
|
10
|
+
spec.email = ['barometer@attackcorp.com']
|
11
|
+
spec.description = %q{Weather via the command line.}
|
12
|
+
spec.summary = %q{Weather via the command line.}
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^spec/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'barometer'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
end
|
data/bin/barometer
ADDED
@@ -0,0 +1,424 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# == Barometer
|
4
|
+
# This is the command line interface to the barometer gem.
|
5
|
+
#
|
6
|
+
# == Examples
|
7
|
+
# This command will measure the weather for the given query.
|
8
|
+
# barometer berlin
|
9
|
+
#
|
10
|
+
# Other examples:
|
11
|
+
# barometer --yahoo 90210
|
12
|
+
# barometer --verbose 'new york'
|
13
|
+
#
|
14
|
+
# == Usage
|
15
|
+
# barometer [options] query
|
16
|
+
#
|
17
|
+
# For help use: barometer -h
|
18
|
+
#
|
19
|
+
# Options:
|
20
|
+
# -v, --version Display the version, then exit
|
21
|
+
# -V, --verbose Verbose output
|
22
|
+
# -t, --timeout seconds until service queries will timeout
|
23
|
+
# -z, --timezone Enhance Timezone
|
24
|
+
# -m, --metric measure in metric
|
25
|
+
# -i, --imperial measure in imperial
|
26
|
+
# --wunderground add wunderground as a source
|
27
|
+
# --yahoo add yahoo as a source
|
28
|
+
# --bug add weather_bug as a source
|
29
|
+
# --noaa add NOAA as a source
|
30
|
+
# -p, --pop pop threshold used to determine wet?
|
31
|
+
# -s, --wind wind speed threshold used to determine windy?
|
32
|
+
# -a, --at time/date used to determine when to calculate summary
|
33
|
+
#
|
34
|
+
# == Author
|
35
|
+
# Mark G
|
36
|
+
# http://github.com/attack/barometer
|
37
|
+
#
|
38
|
+
# == Copyright
|
39
|
+
# Copyright (c) 2009-2013 Mark G. Licensed under the MIT License:
|
40
|
+
# http://www.opensource.org/licenses/mit-license.php
|
41
|
+
|
42
|
+
require 'barometer'
|
43
|
+
|
44
|
+
require 'optparse'
|
45
|
+
require 'ostruct'
|
46
|
+
require 'time'
|
47
|
+
require 'date'
|
48
|
+
require 'yaml'
|
49
|
+
|
50
|
+
# file where API keys are stored
|
51
|
+
KEY_FILE = File.expand_path(File.join('~', '.barometer'))
|
52
|
+
|
53
|
+
class App
|
54
|
+
attr_reader :options
|
55
|
+
|
56
|
+
def initialize(arguments, stdin)
|
57
|
+
@arguments = arguments.dup
|
58
|
+
|
59
|
+
# Set defaults
|
60
|
+
@options = OpenStruct.new
|
61
|
+
@options.timeout = 15
|
62
|
+
@options.timezone = false
|
63
|
+
@options.metric = true
|
64
|
+
@options.sources = []
|
65
|
+
@options.verbose = false
|
66
|
+
@options.at = nil
|
67
|
+
@options.default = true
|
68
|
+
|
69
|
+
# thresholds
|
70
|
+
@options.windy_m = 10
|
71
|
+
@options.windy_i = 7
|
72
|
+
@options.pop = 50
|
73
|
+
end
|
74
|
+
|
75
|
+
# Parse options, check arguments, then process the command
|
76
|
+
def run
|
77
|
+
if parsed_options? && arguments_valid?
|
78
|
+
puts "Start at #{DateTime.now}\n\n" if @options.verbose
|
79
|
+
output_options if @options.verbose # [Optional]
|
80
|
+
|
81
|
+
process_command
|
82
|
+
|
83
|
+
puts "\nFinished at #{DateTime.now}" if @options.verbose
|
84
|
+
else
|
85
|
+
output_usage
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
protected
|
90
|
+
|
91
|
+
# future options
|
92
|
+
#
|
93
|
+
# time: -a --at
|
94
|
+
#
|
95
|
+
def parsed_options?
|
96
|
+
# Specify options
|
97
|
+
opt = OptionParser.new
|
98
|
+
opt.on('-v', '--version') { output_version ; exit 0 }
|
99
|
+
opt.on('-h', '--help') { output_help }
|
100
|
+
opt.on('-V', '--verbose') { @options.verbose = true }
|
101
|
+
opt.on('-a n', '--at n') {|n| @options.at = Time.parse(n.to_s) }
|
102
|
+
opt.on('-t n', '--timeout n') {|n| @options.timeout = n }
|
103
|
+
opt.on('-z', '--timezone') { @options.timezone = true }
|
104
|
+
opt.on('-m', '--metric') { @options.metric = true }
|
105
|
+
opt.on('-i', '--imperial') { @options.metric = false }
|
106
|
+
opt.on('--wunderground') { @options.sources << :wunderground; @options.default = false }
|
107
|
+
opt.on('--yahoo') { @options.sources << :yahoo; @options.default = false }
|
108
|
+
opt.on('--bug') { @options.sources << :weather_bug; @options.default = false }
|
109
|
+
opt.on('--noaa') { @options.sources << :noaa; @options.default = false }
|
110
|
+
opt.on('-p n', '--pop n') {|n| @options.pop = n.to_i || 50 }
|
111
|
+
opt.on('-s n', '--wind n') {|n| @options.metric ? @options.windy_m = n.to_f || 10 : @options.windy_i = n.to_f || 7 }
|
112
|
+
|
113
|
+
opt.parse!(@arguments) rescue return false
|
114
|
+
|
115
|
+
process_options
|
116
|
+
true
|
117
|
+
end
|
118
|
+
|
119
|
+
def config_weather_bug
|
120
|
+
if File.exists?(KEY_FILE)
|
121
|
+
keys = YAML.load_file(KEY_FILE)
|
122
|
+
if keys["weather_bug"] && keys["weather_bug"]["code"]
|
123
|
+
code = keys["weather_bug"]["code"].to_s
|
124
|
+
else
|
125
|
+
bug_key_message
|
126
|
+
exit
|
127
|
+
end
|
128
|
+
else
|
129
|
+
File.open(KEY_FILE, 'w') {|f| f << "\nweather_bug:\n code: API_CODE" }
|
130
|
+
bug_key_message
|
131
|
+
exit
|
132
|
+
end
|
133
|
+
{ :weather_bug => { :keys => { :code => code } } }
|
134
|
+
end
|
135
|
+
|
136
|
+
# Performs post-parse processing on options
|
137
|
+
def process_options
|
138
|
+
@options.sources << :wunderground if @options.default
|
139
|
+
@options.sources = @options.sources.uniq
|
140
|
+
if @options.sources.include?(:weather_bug)
|
141
|
+
@options.sources.delete(:weather_bug)
|
142
|
+
@options.sources << config_weather_bug
|
143
|
+
end
|
144
|
+
Barometer.config = { 1 => @options.sources }
|
145
|
+
Barometer.timeout = @options.timeout
|
146
|
+
end
|
147
|
+
|
148
|
+
def output_options
|
149
|
+
puts "Options:\n"
|
150
|
+
|
151
|
+
@options.marshal_dump.each do |name, val|
|
152
|
+
puts " #{name} = #{val}"
|
153
|
+
end
|
154
|
+
puts
|
155
|
+
end
|
156
|
+
|
157
|
+
# True if required arguments were provided
|
158
|
+
def arguments_valid?
|
159
|
+
true if (@arguments.length >= 1 || @options.web)
|
160
|
+
end
|
161
|
+
|
162
|
+
def output_help
|
163
|
+
output_version
|
164
|
+
end
|
165
|
+
|
166
|
+
def output_usage
|
167
|
+
puts "Usage: "
|
168
|
+
puts "barometer [options] query"
|
169
|
+
puts
|
170
|
+
puts "For help use: barometer -h"
|
171
|
+
puts
|
172
|
+
puts "options:"
|
173
|
+
puts " -v, --version Display the version, then exit"
|
174
|
+
puts " -V, --verbose Verbose output"
|
175
|
+
puts " -t, --timeout seconds until service queries will timeout"
|
176
|
+
puts " -z, --timezone Force timezone query"
|
177
|
+
puts " -m, --metric measure in metric"
|
178
|
+
puts " -i, --imperial measure in imperial"
|
179
|
+
puts " --wunderground add wunderground as a source"
|
180
|
+
puts " --yahoo add yahoo as a source"
|
181
|
+
puts " --bug add weather_bug as a source"
|
182
|
+
puts " --noaa add NOAA as a source"
|
183
|
+
puts " -p, --pop pop threshold used to determine wet?"
|
184
|
+
puts " -s, --wind wind speed threshold used to determine windy?"
|
185
|
+
puts " -a, --at time/date used to determine when to calculate summary"
|
186
|
+
end
|
187
|
+
|
188
|
+
def output_version
|
189
|
+
puts "#{File.basename(__FILE__)} version #{Barometer::VERSION}"
|
190
|
+
end
|
191
|
+
|
192
|
+
def process_command
|
193
|
+
barometer = Barometer.new(@arguments.join(" "))
|
194
|
+
begin
|
195
|
+
if @options.verbose
|
196
|
+
Barometer::debug!
|
197
|
+
div(char="*")
|
198
|
+
puts "DEBUG LOG"
|
199
|
+
blank
|
200
|
+
end
|
201
|
+
barometer.measure(@options.metric) if barometer
|
202
|
+
blank if @options.verbose
|
203
|
+
pretty_output(barometer) if barometer.weather
|
204
|
+
rescue Barometer::OutOfSources
|
205
|
+
puts
|
206
|
+
puts " SORRY: your query did not provide any results"
|
207
|
+
puts
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
#
|
213
|
+
# HELPERS
|
214
|
+
#
|
215
|
+
|
216
|
+
@level = 1
|
217
|
+
|
218
|
+
def y(value)
|
219
|
+
value ? "yes" : "no"
|
220
|
+
end
|
221
|
+
|
222
|
+
def div(char="#")
|
223
|
+
puts char*50
|
224
|
+
end
|
225
|
+
|
226
|
+
def title(title, level=1)
|
227
|
+
@level = level
|
228
|
+
puts "#{" " * @level}-- #{title} --"
|
229
|
+
end
|
230
|
+
|
231
|
+
def value(title, value)
|
232
|
+
puts "#{" " * @level}#{title}: #{value}" unless value.nil?
|
233
|
+
end
|
234
|
+
|
235
|
+
def blank
|
236
|
+
puts
|
237
|
+
end
|
238
|
+
|
239
|
+
def section(title, level=1, show_blank=true)
|
240
|
+
@level = level
|
241
|
+
title(title, level); yield; blank if show_blank
|
242
|
+
end
|
243
|
+
|
244
|
+
def pretty_hash(hash)
|
245
|
+
return unless hash.is_a?(Hash)
|
246
|
+
hash.each { |k,v| value(k,v) }
|
247
|
+
end
|
248
|
+
|
249
|
+
def pretty_summary(s)
|
250
|
+
return unless s
|
251
|
+
section("AVERAGES") do
|
252
|
+
pretty_hash({
|
253
|
+
"humidity" => s.humidity.to_i, "temperature" => s.temperature,
|
254
|
+
"wind" => s.wind, "pressure" => s.pressure,
|
255
|
+
"dew_point" => s.dew_point, "heat_index" => s.heat_index,
|
256
|
+
"wind_chill" => s.wind_chill, "visibility" => s.visibility })
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
def pretty_query(q)
|
261
|
+
return unless q
|
262
|
+
section("ORIGINAL QUERY", 1) do
|
263
|
+
pretty_hash({
|
264
|
+
"Query" => q.q, "Format" => q.format,
|
265
|
+
"Country Code" => q.country_code })
|
266
|
+
end
|
267
|
+
if q.geo
|
268
|
+
section("GEO", 2) do
|
269
|
+
pretty_hash({
|
270
|
+
"Address" => q.geo.address, "Query" => q.geo.query,
|
271
|
+
"Locality" => q.geo.locality, "Region" => q.geo.region,
|
272
|
+
"Country" => q.geo.country, "Country Code" => q.geo.country_code,
|
273
|
+
"Latitude" => q.geo.latitude, "Longitude" => q.geo.longitude })
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
def pretty_location(l)
|
279
|
+
return unless l
|
280
|
+
section("LOCATION", 2) do
|
281
|
+
pretty_hash({
|
282
|
+
"ID" => l.id, "Name" => l.name,
|
283
|
+
"City" => l.city, "State Name" => l.state_name,
|
284
|
+
"State Code" => l.state_code, "Country" => l.country,
|
285
|
+
"Country Code" => l.country_code, "Zip Code" => l.zip_code,
|
286
|
+
"Latitude" => l.latitude, "Longitude" => l.longitude })
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
def pretty_station(s)
|
291
|
+
return unless s
|
292
|
+
section("STATION", 2) do
|
293
|
+
pretty_hash({
|
294
|
+
"ID" => s.id, "Name" => s.name,
|
295
|
+
"City" => s.city, "State Name" => s.state_name,
|
296
|
+
"State Code" => s.state_code, "Country" => s.country,
|
297
|
+
"Country Code" => s.country_code, "Zip Code" => s.zip_code,
|
298
|
+
"Latitude" => s.latitude, "Longitude" => s.longitude })
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
def pretty_timezone(t)
|
303
|
+
return unless t
|
304
|
+
section("TIMEZONE", 2) do
|
305
|
+
pretty_hash({ "Long" => t.full, "Code" => t.code, "DST?" => t.dst?,
|
306
|
+
"Now" => t.now(true), "Today" => t.today })
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
def pretty_current(c)
|
311
|
+
return unless c
|
312
|
+
section("CURRENT", 2) do
|
313
|
+
pretty_hash({
|
314
|
+
"Humidity" => c.humidity, "Icon" => c.icon,
|
315
|
+
"Condition" => c.condition, "Temperature" => c.temperature,
|
316
|
+
"Dew Point" => c.dew_point, "Heat Index" => c.heat_index,
|
317
|
+
"Pressure" => c.pressure, "Visibility" => c.visibility,
|
318
|
+
"Wind Chill" => c.wind_chill })
|
319
|
+
pretty_hash({ "Wind" => c.wind.to_s }) if c.wind
|
320
|
+
pretty_hash({ "Sun Rise" => c.sun.rise, "Sun Set" => c.sun.set }) if c.sun
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
def pretty_forecast(f)
|
325
|
+
return unless f
|
326
|
+
section("FOR: #{f.date}", 3) do
|
327
|
+
pretty_hash({
|
328
|
+
"Valid From" => f.starts_at.to_s(true),
|
329
|
+
"Valid Until" => f.ends_at.to_s(true),
|
330
|
+
"Icon" => f.icon, "Description" => f.description,
|
331
|
+
"Condition" => f.condition, "High" => f.high,
|
332
|
+
"Low" => f.low, "POP" => f.pop, "Humidity" => f.humidity })
|
333
|
+
pretty_hash({ "Wind" => f.wind.to_s }) if f.wind
|
334
|
+
pretty_hash({ "Sun Rise" => f.sun.rise, "Sun Set" => f.sun.set }) if f.sun
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
def pretty_forecasts(forecasts)
|
339
|
+
return unless forecasts
|
340
|
+
section("FORECAST(s)", 3, false) do
|
341
|
+
blank
|
342
|
+
forecasts.each do |forecast|
|
343
|
+
pretty_forecast(forecast)
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
def pretty_response(m)
|
349
|
+
return unless m
|
350
|
+
section(m.source.to_s, 1) do
|
351
|
+
pretty_hash({
|
352
|
+
"Source" => m.source,
|
353
|
+
"Metric" => m.metric?, "Success" => m.success?,
|
354
|
+
"Service Time" => "#{(m.response_ended_at - m.response_started_at)} s"
|
355
|
+
})
|
356
|
+
end
|
357
|
+
section("MODIFIED QUERY", 2) do
|
358
|
+
pretty_hash({ "Query" => m.query, "Format" => m.format })
|
359
|
+
end
|
360
|
+
pretty_location(m.location)
|
361
|
+
pretty_station(m.station)
|
362
|
+
pretty_timezone(m.timezone)
|
363
|
+
pretty_current(m.current)
|
364
|
+
pretty_forecasts(m.forecast)
|
365
|
+
end
|
366
|
+
|
367
|
+
def pretty_responses(w)
|
368
|
+
return unless w
|
369
|
+
section("MEASUREMENTS", 1) do
|
370
|
+
blank
|
371
|
+
w.responses.each do |m|
|
372
|
+
pretty_response(m)
|
373
|
+
end
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
def pretty_info(w)
|
378
|
+
title("INFO", 1)
|
379
|
+
value("GitHub", "http://github.com/attack/barometer")
|
380
|
+
value("Barometer Version", Barometer::VERSION)
|
381
|
+
value("Total Time", "#{(w.end_at - w.start_at)} s")
|
382
|
+
end
|
383
|
+
|
384
|
+
def pretty_output(barometer)
|
385
|
+
weather = barometer.weather
|
386
|
+
if weather
|
387
|
+
div
|
388
|
+
puts "#"
|
389
|
+
puts "# #{weather.default.location.name || barometer.query.q}"
|
390
|
+
puts "#"
|
391
|
+
div
|
392
|
+
blank
|
393
|
+
pretty_summary(weather)
|
394
|
+
pretty_query(barometer.query)
|
395
|
+
pretty_responses(weather)
|
396
|
+
pretty_info(weather)
|
397
|
+
div("-")
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
def bug_key_message
|
402
|
+
puts
|
403
|
+
puts "MISSING KEYS !!!"
|
404
|
+
puts "Please update the key_file '#{KEY_FILE}' with your weather_bug api key"
|
405
|
+
puts "Get it here: ???"
|
406
|
+
puts "Then, add these lines to the file:"
|
407
|
+
puts "weather_bug:"
|
408
|
+
puts " code: API_CODE"
|
409
|
+
puts
|
410
|
+
end
|
411
|
+
|
412
|
+
# set API keys
|
413
|
+
if File.exists?(KEY_FILE)
|
414
|
+
keys = YAML.load_file(KEY_FILE)
|
415
|
+
if keys["yahoo"] && keys["yahoo"]["app_id"]
|
416
|
+
Barometer.yahoo_placemaker_app_id = keys["yahoo"]["app_id"]
|
417
|
+
end
|
418
|
+
else
|
419
|
+
File.open(KEY_FILE, 'w') {|f| f << "yahoo:\n app_id: YOUR_KEY_KERE" }
|
420
|
+
end
|
421
|
+
|
422
|
+
# Create and run the application
|
423
|
+
app = App.new(ARGV, STDIN)
|
424
|
+
app.run
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: barometer-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark G
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: barometer
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Weather via the command line.
|
56
|
+
email:
|
57
|
+
- barometer@attackcorp.com
|
58
|
+
executables:
|
59
|
+
- barometer
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- barometer-cli.gemspec
|
69
|
+
- bin/barometer
|
70
|
+
- lib/barometer/cli.rb
|
71
|
+
- lib/barometer/cli/version.rb
|
72
|
+
homepage: ''
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.0.0
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Weather via the command line.
|
96
|
+
test_files: []
|