Sha256: 848f63350fae4bba4c28883bd0e8753ccd94e2697217bef74574544f550f2490

Contents?: true

Size: 1021 Bytes

Versions: 1

Compression:

Stored size: 1021 Bytes

Contents

#!/usr/bin/env ruby
require 'darksky-ruby/trollop'
require 'darksky-ruby'


opts = Trollop::options do
  banner "darksky [options] <LAT,LON>"
  opt :key, 'API secret key', type: :string
  opt :loc, 'Location (latitude,longtitude)', type: :string
  opt :log, 'Log file', type: :string
  opt :time, 'Timestamp for Time Machine request', type: :string
  opt :verbose, 'Verbose mode'
end

if opts[:log_given]
  Neko.logger = Logger.new(opts[:log])
  Neko.logger.level = Logger::WARN
end

if opts[:verbose]
  Neko.logger = Logger.new(STDOUT) unless opts[:log_given]
  Neko.logger.level = Logger::DEBUG
end
log = Neko.logger

log.debug("Command line arguments: #{opts}")

loc = opts[:loc]
loc ||= ARGV.shift

Trollop::die :loc, "is missing" if loc.nil?

api = DarkskyAPI.new(key: opts[:key])
api.blocks = {minutely: false, hourly: false, daily: false, alerts: false, flags: false}

if opts[:time_given]
  data = api.timemachine(loc: loc, ts: opts[:time])
else 
  data = api.forecast(loc: loc)
end

require 'pp'
pp data if data

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
darksky-ruby-0.0.2 bin/darksky