twitter4r を使用した twitter client for ruby
引数を与えるとpost & get,
引数がないと get のみ
#!/usr/local/bin/ruby require 'rubygems' gem( 'twitter4r', '>=0.3.0' ) require 'twitter' require 'time' USERNAME = 'username' PASSWORD = 'password' message = nil if ARGV.size > 0 then message = ARGV.join( ' ' ) end client = Twitter::Client.new( :login => USERNAME, :password => PASSWORD ) if message != nil then post_status = client.status( :post, message ) end statuses = [ ] timeline = client.timeline_for( :friends ) do |status| statuses.push( status ) end statuses.reverse.each{ |status| datetime = status.created_at.to_s.split( / / ) puts "#{status.user.screen_name} : #{status.text} [ #{datetime[ 1 ]} #{datetime[ 2 ]} #{datetime[ 4 ].slice( 0..4 ) } ]" }
結果はこんな感じ
takahiro@takahiro-desktop:~/work/ruby/twitter$ ./main.rb calvinongcg : @sidneymohede haha... i did that too this morning while on my way to work... Have a great day... it's raining in Spore... [ 06 May 10:06 ] wakachamo : @Biansta b'as noites :D [ 06 May 10:07 ] saki28 : おはようごじますー [ 06 May 10:20 ] wakachamo : Peter Cushing lives in Whitstable... [ 06 May 10:23 ] wakachamo : I agree with @LetterM. This is the best QI moment EVER. http://bit.ly/YjVrp [ 06 May 10:25 ] wakachamo : @taktoniboshi おはようございまーす [ 06 May 10:36 ] wakachamo : @LetterM they say of the acropolis where the parthenon is... [ 06 May 10:36 ] dkdn : こんな辺境の地の映画館がここまで混むとは…ゴールデン・ウィーク最終日おそるべし… [ 06 May 10:42 ] dkdn : あまりの混み具合に映画館から退散。負けた…負けたのだ! [ 06 May 10:44 ] dkdn : さて映画難民。帰宅してもすることない。 [ 06 May 11:01 ] wakachamo : @sandkatt prettyyyy :D what do you think of the RC so far? [ 06 May 11:12 ] wakachamo : [Digg] Caroline Costa Sings Hurt by Christina Aguilera http://tinyurl.com/dmna74 [ 06 May 11:13 ] wakachamo : @sandkatt yeah, I bet the spaced romaji feels a little awkward :P [ 06 May 11:14 ] gumpreza : @chicago2cali amen. levin is gold. [ 06 May 11:28 ] gumpreza : @brendanlewis do you have build 7100? i know what you speak of but mine doesn't do that. [ 06 May 11:28 ] wakachamo : @LetterM I swear you make posts on tumblr at the speed of light [ 06 May 11:34 ] wakachamo : @LetterM YOU JUST MADE ANOTHER ONE WTF DDDDDDDDDD8 [ 06 May 11:39 ] superhoge : 日本語テスト from twitter4r [ 06 May 11:41 ] superhoge : rails で家計簿アプリを試作中 [ 06 May 11:42 ] metaphoricwords : Windowsダンプの極意を読む。 [ 06 May 11:44 ] takahiro@takahiro-desktop:~/work/ruby/twitter$
簡単過ぎる。
いい時代になったなぁ。