Ruby twitter bot in 25 lines

Posted: November 30th, 2008 | Author: Andy | Filed under: ruby | No Comments »

Using ruby to make a tiny twitter bot is so simple. So in 25 lines I used the twitter and hpricot gems to make a bot that pulls a random quote from the puerile b3ta.com/talk.

# Rakefile

require 'rake'
require 'twitter'
require 'hpricot'
require 'open-uri'
namespace :b3ta do
  desc 'find a random quote from b3ta.com/talk and post it to twitter'
  task :random_quote do
    hdoc = Hpricot(open('http://www.b3ta.com/talk').read)
    subs = []
    hdoc.search(".post1, .post2") do |post|
      username, subject = '', ''
      post.search(".username") do |un|
        username = un.inner_html
      end
      post.search("b") do |b|
        subject = b.inner_html.to_s.gsub(/<\/?[^>]*>/, "")
      end
      subs << "\"#{subject}\" #{username}" if subject != ''
    end
    message = subs[rand(subs.size - 1)]
    twitter = Twitter::Base.new('twitter_username','twitter_password')
    twitter.post(message)
    puts message
  end
end

To set it up and running, just put in a real twitter account and use “rake b3ta:random_quote”. Simple. Ok it may lack any error checking what so ever, but its still amazing what you can do with Ruby with such little code. (check out the rather offensive twitter feed here)


London (harder, better, faster, stronger)

Posted: November 29th, 2008 | Author: Andy | Filed under: video | No Comments »

I found this scanning around Vimeo HD.


Mephisto to WordPress

Posted: November 29th, 2008 | Author: Andy | Filed under: blog | No Comments »

Bye bye mephisto and welcome back WordPress. I used a little magic to get the old posts from mephisto to this new system as mephisto lacked an export feature.

1) Edit mephisto to give you all your post in one Atom document. Have a look in app/controller/feed/feed_controller.rb and change the limits of 15 to over the amount of posts you have.

2) WordPress doesn’t like Atom, so convert your to RSS 2.0. I used a cool little webserice for this. With this service we can output something to our computer with curl
 

curl http://atom2rss.semiologic.com/?atom=http%3A%2F%2Fmibly.com%2Ffeed%2F > old_posts.xml

3) Upload old_posts.xml to you smashing new wordpress blog.

Now this doesn’t import any comments which is a shame.