Sha256: 02cb643f1bc343bfaebb3986d9f62925aa086e37f6f18aae07d195a86301daad

Contents?: true

Size: 1.93 KB

Versions: 2

Compression:

Stored size: 1.93 KB

Contents

#!/usr/bin/env ruby
require 'optparse'
params = ARGV.getopts(nil, "module:news", "output:log", "date")

$:.unshift(File.expand_path('../../lib', __FILE__)) if $0 == __FILE__

require 'consadole_aggregator'

output = case params['output']
         when 'log'
           require 'logger'
           path = File.expand_path('../../log', __FILE__) + '/exec_result.log'
           log = Logger.new(path)
           puts "output to #{path}"
           ->(element){
             if element.kind_of?(ConsadoleAggregator::Live::Timeline)
               log.debug ConsadoleAggregator::Helper.concat(element.to_s, hashtag:'#consadole')
             else
               title, url = element[:title], element[:url]
               log.debug ConsadoleAggregator::Helper.concat(title, url:url, hashtag:'#consadole')
             end
           }
         when 'twitter'
           require 'oauth'
           require 'rubytter'
           ACCOUNT = YAML.load_file('account.yaml')
           oauth = Rubytter::OAuth.new(ACCOUNT['consumer']['key'], ACCOUNT['consumer']['secret'])
           access_token = OAuth::AccessToken.new(oauth.create_consumer, ACCOUNT['access']['key'], ACCOUNT['access']['secret'])
           t = OAuthRubytter.new(access_token)
           ->(element){
             if element.kind_of?(ConsadoleAggregator::Live::Timeline)
               t.update ConsadoleAggregator::Helper.concat(element.to_s, hashtag:'#consadole')
             else
               title, url = element[:title], element[:url]
               t.update ConsadoleAggregator::Helper.concat(title, url:url, hashtag:'#consadole')
             end
           }
         end

case params['module']
when 'news'
  modules = ConsadoleAggregator::News.constants.map{ |k| ConsadoleAggregator::News.const_get(k).new }
  modules.each{ |m| m.update &output }
when 'live'
  reservation_time = params['date'] ? Time.parse(params['date']) : nil
  ConsadoleAggregator::Live.reserve(reservation_time).execute &output
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
consadole_aggregator-0.1.1 bin/consadole_aggregator
consadole_aggregator-0.1.0 bin/consadole_aggregator