I have whipped up a short script to update Facebook’s status, Twitter, and Kopete’s status all at once. The Facebook portion of the code comes directly from Kerry Buckley’s script
To make use of my script, you need:
- Ruby 1.8
- John Nunemaker’s excellent twitter gem:
sudo gem install twitter -y. - KDE’s Kopete installed and running.
To use this code, edit the constants on top to set your login details, and simply execute status "my status message". Kopete and Twitter will be updated as you expect, but Facebook will appear as <yourname> is saying "my status message". Everything before the ‘saying’ is beyond my control, so I have to reformat the message so that it makes grammatical sense. It’d be nice if Facebook didn’t have this constraint.
To clear your messages, type status reset. This sends an empty message.
Note: this code is still experimental - use at your own risk! The code:
- #!/usr/bin/env ruby
- FACEBOOK<em>EMAIL = ‘name@example.com’
- FACEBOOK</em>PASSWORD = ‘mypassword’
- TWITTER<em>EMAIL = ‘name@example.com’
- TWITTER</em>PASSWORD =‘mypassword’
- USERAGENT = ‘Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/XX (KHTML, like Gecko) Safari/YY’
- class StatusUpdater
- require ‘net/http’
- require ‘net/https’
- require ‘rexml/document’
- require ‘twitter’
- include REXML
- def initialize(options = {})
- @options = {
- :useragent => USERAGENT,
- :fb<em>email => FACEBOOK</em>EMAIL,
- :fb<em>pass => FACEBOOK</em>PASSWORD,
- :tw<em>email => TWITTER</em>EMAIL,
- :tw<em>pass => TWITTER</em>PASSWORD
- }.merge(options)
- end
- def update<em>twitter(status)
- twitter = Twitter::Base.new(TWITTER</em>EMAIL, TWITTER<em>PASSWORD)
- twitter.update(status)
- end
- def update</em>kopete(status)
- status = status.gsub(’\n’, ’ ‘)
- system("dcop kopete KopeteIface setAway \"#{status}\" false")
- end
- def update<em>facebook(status)
- status = "saying \"#{status.gsub(‘\n’, ’ ‘)}\"" unless status == ”
- # Log in to FaceBook
- req = Net::HTTP::Post.new ‘/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php’
- req.set</em>form<em>data({‘email’ => @options[:fb</em>email], ‘pass’ => @options[:fb<em>pass]})
- http = Net::HTTP.new(‘login.facebook.com’, 443)
- http.use</em>ssl = true
- http.start do |session|
- resp = http.request req
- @cookies = resp[‘Set-Cookie’].split(’, ‘).select { |line| line =~ /^\S*=/}.collect { |cookie| cookie.split(/; ?/)[0] }.join ’; ‘
- end
- http = Net::HTTP.new ‘m.facebook.com’
- http.start do |session|
- # Retrieve the [mobile] home page, to get the form ID
- resp = session.get ‘/home.php’, {‘User-Agent’ => USERAGENT, ‘Cookie’ => @cookies}
- doc = Document.new(resp.body)
- post<em>form</em>id = (XPath.first doc, "//input[@name=’post<em>form</em>id’]/@value").to<em>s
- # Post the status
- resp = session.post ‘/home.php’,"post</em>form<em>id=#{URI.encode post</em>form<em>id}&status=#{URI.encode status}&update=Update",{‘User-Agent’ => USERAGENT, ‘Content-Type’ => ‘application/x-www-form-urlencoded’,‘Referer’ => ‘http://m.facebook.com/home.php’,‘Cookie’ => @cookies}
- end
- end
- def update(status)
- status = status.gsub("\n", ‘\n’)
- update</em>methods = self.methods.select {|method<em>name| method</em>name =~ /^update<em>[a-z]{1,}$/}
- update</em>methods.each do |update<em>method|
- self.send(update</em>method, status)
- end
- end
- end
- status = ARGV.first
- status = "" if status == ‘reset’
- updater = StatusUpdater.new
- updater.update(status)
