counter

20081128

I just made script that fetch twitter timeline and display to Snarl.

It's only Snarl + Ruby. Snarl is system notification tool that like Growl for Mac OS X. You have to download Snarl from here(Snarl :: Homepage). Also need following ruby libraries.

Script

# Simplest twitter client (only for gets)
# twiget.rb
# usage:
# ruby twiget.rb 10
# => friends timeline から 最新10件取得
require 'net/http'
require 'kconv'
require 'rubygems'
require 'snarl'
require 'json'
max_count = ARGV.shift.to_i
Net::HTTP.version_1_2
req = Net::HTTP::Get.new('/statuses/friends_timeline.json')
req.basic_auth "user_id", "password" # user_id, password を自分のものにしてね。
# proxyサーバを適当に変更してね。
Net::HTTP::Proxy('proxy_server', 8080).start('twitter.com') {|http|
res = http.request(req)
if res.code == '200'
result = JSON.parser.new(res.body).parse()
result.length.times do |i|
exit 0 if i >= max_count
puts screen_name = result[i]["user"]["screen_name"]
puts text = result[i]["text"]
Snarl.show_message("Twiget: #{screen_name}", "#{text}", nil, 10)
sleep 1
end
else
Snarl.show_message("Twiget error", "code is #{res.code}", nil, 10)
end
}
view raw gistfile1.rbx hosted with ❤ by GitHub

Usage

You have to change following settings.
  • user_id
  • password
  • proxy_serer
  • proxy port
Command line parameter is ...
  • Num of messages

No comments:

Followers

About Me

Tokyo, Japan
http://iddy.jp/profile/snaka/