Ruby twitter bot in 25 lines

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)

Mephisto to WordPress

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.

iPlayerlist map

So here is the first thing I’ve managed to get out of Opencalais. Its not really that interesting but a few people seem to like it.

iPlayerlist map

So what you are looking at is all the programmes on iPlayer whose synopsis contains something that is of geographical importance. Now thanks to Opencalais’ new beta we get the longitutude and latitude of a given point (without it, you would have to use something like GeoNames) hence a point on the map. Simple really.

Whats in the mix?

  • All the same old iPlayerlist stuff, DB, html scraping, and what have you.
  • Httparty – makes dealing with restful APIs rather interesting.
  • Google maps.
  • Facebox – for the lightbox thing.

So its another dumb map mashup. Now the real question is does it add anything new for the user? Well I’m not sure. I’m going to add a few colours to the markers, and output the geolocations in KML if I get the time.

Opencalais + iPlayerlist

Opencalais is one of those Web 3.0 (sorry) services which is really rather interesting. Basically if you throw plain text at it will return the concepts it finds. For example it would recognise the Royal Albert Hall as a place and London as a city. The output is in RDF, yay.

As you might have guessed I’m thwacking the data from iPlayerlist (which is essentially bbc.co.uk/programmes) through it and see what we get.

Well its made me giggle. You get some cool stuff like programmes relating to Cities, People and Nations, but also some rather random topics. Medical Conditions is my favorite, you would be surprised how many programmes pop up in that topic.

So keep you eye out, it won’t be long before you will be able to subscribe to iPlayer shows relating to “sore throats” :)

iPlayerlist is back, less sucky and smells of lemon

Ok, I was stunned by the new iPlayer site to such a degree that I let iPlayerlist die for a bit. However, after a few people got in touch asking me to carry on I thought I best had do. So its back!

There really isn’t too much different than the old one from the face of it, but underneath its brand spanking new and loads cleaner. This is mainly thanks to iplayer now outputting Atom feeds. Thanks for that :)

One of the coolest things I’m working on is the idea that a user can sign in and subscribe to a given series. It’s actually up and running now, but not really ready for the whole world yet. Here is a link to what I’m currently watching on iPlayer.

Now that sort of thing opens the door to a whole raft of cool code writing fun. Suggestions welcome btw.

iPlayer v2 is wonderful!

I have to hand it to the people at the beeb who work on iPlayer. The new site is loads better and putting radio and TV together is what I really wanted to see more of. So well done all around, it’s brilliant.

What does this mean for iPlayerlist? Well, I’m not sure, I still use my little site as I do like the lo-finess but to be honest, the new iPlayer site is much better for everybody else.

Perhaps I should change the tagline to “making the unmissable, slightly shitter”?

Should I bother continuing to maintain it?

The popularity of the features iPhone and iPod version of iplayerlist is making me think that I should. The fact that most users of the site are using these apple products is rather interesting. Getting linked from apple.com must have done something (grin), but the fact that they keep returning must mean its doing something right.

So I’m torn. Should I go on to try something else, or try and fix this for more devices and other such shenanigans?