#!/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