bin/barometer in attack-barometer-0.5.0 vs bin/barometer in attack-barometer-0.6.0
- old
+ new
@@ -27,16 +27,18 @@
# Options:
# -v, --version Display the version, then exit
# -V, --verbose Verbose output
# -t, --timeout seconds until service queries will timeout
# -g, --geocode Force Geocoding of query
+# -z, --timezone Enhance Timezone
# -m, --metric measure in metric
# -i, --imperial measure in imperial
# --wunderground add wunderground as a source
# --yahoo add yahoo as a source
# --google add google as a source
# --weather add weather.com as a source
+# --bug add weather_bug as a source
# -p, --pop pop threshold used to determine wet?
# -s, --wind wind speed threshold used to determine windy?
# -a, --at time/date used to determine when to calculate summary
#
# Web Demo:
@@ -62,11 +64,11 @@
require 'date'
require 'yaml'
# file where API keys are stored
KEY_FILE = File.expand_path(File.join('~', '.barometer'))
-BAROMETER_VERSION = '0.5.0'
+BAROMETER_VERSION = '0.6.0'
class App
attr_reader :options
@@ -75,10 +77,11 @@
# Set defaults
@options = OpenStruct.new
@options.timeout = 15
@options.geocode = false
+ @options.timezone = false
@options.metric = true
@options.sources = []
@options.verbode = false
@options.web = false
@options.at = nil
@@ -118,16 +121,18 @@
opt.on('-h', '--help') { output_help }
opt.on('-V', '--verbose') { @options.verbose = true }
opt.on('-a n', '--at n') {|n| @options.at = Time.parse(n.to_s) }
opt.on('-t n', '--timeout n') {|n| @options.timeout = n }
opt.on('-g', '--geocode') { @options.geocode = true }
+ opt.on('-z', '--timezone') { @options.timezone = true }
opt.on('-m', '--metric') { @options.metric = true }
opt.on('-i', '--imperial') { @options.metric = false }
opt.on('--wunderground') { @options.sources << :wunderground; @options.default = false }
opt.on('--yahoo') { @options.sources << :yahoo; @options.default = false }
opt.on('--google') { @options.sources << :google; @options.default = false }
opt.on('--weather') { @options.sources << :weather_dot_com; @options.default = false }
+ opt.on('--bug') { @options.sources << :weather_bug; @options.default = false }
opt.on('-p n', '--pop n') {|n| @options.pop = n.to_i || 50 }
opt.on('-s n', '--wind n') {|n| @options.metric ? @options.windy_m = n.to_f || 10 : @options.windy_i = n.to_f || 7 }
# pass these onto vegas
opt.on('-w', '--web') { @options.web = true; ARGV.shift }
@@ -155,20 +160,42 @@
weather_key_message
exit
end
{ :weather_dot_com => { :keys => { :partner => partner_key, :license => license_key } } }
end
+
+ def config_weather_bug
+ if File.exists?(KEY_FILE)
+ keys = YAML.load_file(KEY_FILE)
+ if keys["weather_bug"] && keys["weather_bug"]["code"]
+ code = keys["weather_bug"]["code"].to_s
+ else
+ bug_key_message
+ exit
+ end
+ else
+ File.open(KEY_FILE, 'w') {|f| f << "\nweather_bug:\n code: API_CODE" }
+ bug_key_message
+ exit
+ end
+ { :weather_bug => { :keys => { :code => code } } }
+ end
# Performs post-parse processing on options
def process_options
@options.sources << :wunderground if @options.default
@options.sources = @options.sources.uniq
Barometer.force_geocode = @options.geocode
+ Barometer.enhance_timezone = @options.timezone
if @options.sources.include?(:weather_dot_com)
@options.sources.delete(:weather_dot_com)
@options.sources << config_weather_dot_com
end
+ if @options.sources.include?(:weather_bug)
+ @options.sources.delete(:weather_bug)
+ @options.sources << config_weather_bug
+ end
Barometer.config = { 1 => @options.sources }
Barometer.timeout = @options.timeout
end
def output_options
@@ -204,16 +231,18 @@
puts "options:"
puts " -v, --version Display the version, then exit"
puts " -V, --verbose Verbose output"
puts " -t, --timeout seconds until service queries will timeout"
puts " -g, --geocode Force Geocoding of query"
+ puts " -z, --timezone Force timezone query"
puts " -m, --metric measure in metric"
puts " -i, --imperial measure in imperial"
puts " --wunderground add wunderground as a source"
puts " --yahoo add yahoo as a source"
puts " --google add google as a source"
puts " --weather add weather.com as a source"
+ puts " --bug add weather_bug as a source"
puts " -p, --pop pop threshold used to determine wet?"
puts " -s, --wind wind speed threshold used to determine windy?"
puts " -a, --at time/date used to determine when to calculate summary"
puts
puts " Web Demo:"
@@ -230,11 +259,18 @@
if @options.web
run_web_mode(@arguments.join(" "))
else
barometer = Barometer.new(@arguments.join(" "))
begin
+ if @options.verbose
+ Barometer::debug!
+ div(char="*")
+ puts "DEBUG LOG"
+ blank
+ end
barometer.measure(@options.metric) if barometer
+ blank if @options.verbose
pretty_output(barometer) if barometer.weather
rescue Barometer::OutOfSources
puts
puts " SORRY: your query did not provide any results"
puts
@@ -290,12 +326,12 @@
"wind_chill" => s.wind_chill, "visibility" => s.visibility })
end
section("SUMMARY#{ " (@ #{@options.at})" if @options.at }") do
pretty_hash({
"day?" => s.day?(@options.at), "sunny?" => s.sunny?(@options.at),
- "windy?" => s.windy?(@options.metric ? @options.windy_m : @options.windy_i, @options.at),
- "wet?" => s.wet?(@options.pop,@options.at) })
+ "windy?" => s.windy?(@options.at, @options.metric ? @options.windy_m : @options.windy_i),
+ "wet?" => s.wet?(@options.at, @options.pop) })
end
end
def pretty_query(q)
return unless q
@@ -340,11 +376,12 @@
end
def pretty_timezone(t)
return unless t
section("TIMEZONE", 2) do
- pretty_hash({ "Long" => t.timezone, "Code" => t.code,"DST?" => t.dst? })
+ pretty_hash({ "Long" => t.full, "Code" => t.code, "DST?" => t.dst?,
+ "Now" => t.now(true), "Today" => t.today })
end
end
def pretty_current(c)
return unless c
@@ -399,11 +436,12 @@
return unless m
section(m.source.to_s, 1) do
pretty_hash({
"Measured At" => m.measured_at,
"Source" => m.source, "Time Stamp" => m.utc_time_stamp,
- "Metric" => m.metric?, "Success" => m.success? })
+ "Metric" => m.metric?, "Success" => m.success?,
+ "Service Time" => "#{(m.end_at - m.start_at)} s" })
end
section("MODIFIED QUERY", 2) do
pretty_hash({ "Query" => m.query, "Format" => m.format })
end
pretty_location(m.location)
@@ -421,14 +459,15 @@
pretty_measurement(m)
end
end
end
-def pretty_info
+def pretty_info(w)
title("INFO", 1)
value("GitHub", "http://github.com/attack/barometer")
value("Barometer Version", BAROMETER_VERSION)
+ value("Total Time", "#{(w.end_at - w.start_at)} s")
end
def pretty_output(barometer)
weather = barometer.weather
if weather
@@ -439,11 +478,11 @@
div
blank
pretty_summary(weather)
pretty_query(barometer.query)
pretty_measurements(weather)
- pretty_info
+ pretty_info(weather)
div("-")
end
end
def run_web_mode(query=nil)
@@ -476,9 +515,20 @@
puts "Get it here: ???"
puts "Then, add these lines to the file:"
puts "weather:"
puts " partner: PARTNER_KEY"
puts " license: LICENSE_KEY"
+ puts
+end
+
+def bug_key_message
+ puts
+ puts "MISSING KEYS !!!"
+ puts "Please update the key_file '#{KEY_FILE}' with your weather_bug api key"
+ puts "Get it here: ???"
+ puts "Then, add these lines to the file:"
+ puts "weather_bug:"
+ puts " code: API_CODE"
puts
end
# set API keys
if File.exists?(KEY_FILE)