Skip to content

Instantly share code, notes, and snippets.

@koduki
Created August 8, 2008 21:12
Show Gist options
  • Save koduki/4626 to your computer and use it in GitHub Desktop.
Save koduki/4626 to your computer and use it in GitHub Desktop.
require "rubygems"
require "mechanize"
require "readline"
require "Kconv"
ICONS = ["fate.png", "nanoha.png"]
URL = 'http://www.twitter.com/'
=begin
ruby twitterc.rb name password
or
ruby twitterc.rb name password proxy:port
=end
class Twitter
def login name, password, proxy
@agent = WWW::Mechanize.new
if proxy != nil
uri = proxy.split(/:/)[0]
port = proxy.split(/:/)[1].to_i
@agent.set_proxy(uri, port)
end
page = @agent.get URL + 'login'
login_form = page.forms[1]
login_form["session[username_or_email]"] = name
login_form["session[password]"] = password
@agent.submit(login_form)
end
def set_icon pic
page = @agent.get URL + 'account/picture'
pic_form = page.forms[0]
pic_form.file_uploads[0].file_name = pic
@agent.submit(pic_form) rescue nil
end
def update msg
page = @agent.get URL + 'home'
update_form = page.forms[0]
update_form['status'] = msg.toutf8
@agent.submit(update_form) rescue nil
end
end
t = Twitter.new
t.login ARGV[0], ARGV[1], ARGV[2]
puts "What are you doing?"
cnt = 0
while (msg = Readline::readline("Twitter:> "))
break if msg == "quit"
t.set_icon ICONS[cnt % ICONS.size]
cnt += 1
puts "change icon."
t.update msg
puts "updated"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment