Sha256: 4f197ba08564398571696102273165793874e4fb181535a824175deb88cbaddc

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

#!/usr/bin/env ruby

$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'twhere'
require 'optparse'

config_file = nil

OptionParser.new do |opts|
  opts.banner = 'usage: twhere.rb [options]'

  opts.on('-c', '--config FILE', 'specify config file') do |c|
    config_file = c
  end

  opts.on_tail('-h', '--help', 'show this message') do
    puts opts
    exit
  end

  opts.on_tail('--version', 'show version') do
    version = YAML::load(File.open(File.join(File.dirname(__FILE__), '..', 'VERSION.yml')))
    puts "#{version[:major]}.#{version[:minor]}.#{version[:patch]}"
    exit
  end
end.parse!

# load config
config = YAML::load(File.open(config_file))

# load known locations
locations = YAML::load(File.open(config[:twhere][:locations_file]))

# load template
template = File.read(config[:twhere][:template_file])

# load saved tweets (or don't)
tweets = []
begin
  tweets = YAML::load(File.open(config[:twhere][:tweets_file])) if config[:twhere][:tweets_file]
rescue Errno::ENOENT
end

# create Twhere instance and puts result
twhere = Twhere.new(locations, template, config[:twitter][:username], config[:twitter][:password], config[:google_maps][:api_key], tweets)
puts twhere.result

# save tweets to file
File.open(config[:twhere][:tweets_file], 'w') { |f| f.puts tweets.to_yaml } if config[:twhere][:tweets_file]

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sarnesjo-twhere-0.0.7 bin/twhere