Class: Twitter2MixiVoice::Application
- Inherits:
-
Object
- Object
- Twitter2MixiVoice::Application
- Defined in:
- lib/application.rb
Overview
This class provides mixi bot application.
Constant Summary collapse
- Posted_Tweets_Dir =
constants
File.join(ENV["HOME"], ".twitter2mixivoice")
- Posted_File_Name =
"posted_tweets.yml"
Class Method Summary collapse
-
.run(args) ⇒ Object
Run Application.
Class Method Details
.run(args) ⇒ Object
Run Application.
- *args
-
command line options.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/application.rb', line 35 def self.run(args) # parse arguments. = Options.new(args, Twitter2MixiVoice::version) # # check options. # if [:invalid_argument] $stderr.puts [:invalid_argument] [:show_help] = true end if [:show_version] $stdout.puts [:show_version] return Success end if [:show_help] $stderr.puts .opts.to_s return Error end result = Error begin # login to twitter. twitter = login_to_twitter([:twitter_id], [:twitter_password]) # login to mixi. mixi = login_to_mixi([:mixi_email], [:mixi_password]) # read cache tweets from YAML file. posted_tweets = read_tweets(Posted_Tweets_Dir, Posted_File_Name) # get tweets from twitter. tweets = twitter.get_tweets_from_timeline # post twitter tweet to mixi voice. tweets.each do |tweet| if (!posted_tweets.has_key?(tweet.id)) mixi.post_voice(tweet.text) posted_tweets[tweet.id] = tweet $stdout.puts "tweet -> voice : id = #{tweet.id}, text = #{tweet.text}" end end # write YAML file from cache tweets. result = write_tweets(Posted_Tweets_Dir, Posted_File_Name, posted_tweets) result = Success rescue MixiException => e $stderr.puts "Raise MixiException : #{e.to_s}" result = Error rescue TwitterClientException => e $stderr.puts "Raise MixiException : #{e.to_s}" result = Error rescue Exception => e $stderr.puts "Raise Exception : #{e.to_s}" result = Error end return result end |