Posted: December 13th, 2008 | Author: Andy | Filed under: ruby, tv | No Comments »

Sometimes I get involved in some internet japes that are only there to make me giggle. The latest is the twitter bot, @robot_santa. So on twitter he’s telling anybody that they are very naughty, to much amusement and bemusement. For those who don’t know, he stared in an awesome episode of Futurama and basically blew up everybody on XMAS eve.
God knows what I’ll do with him now…
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.
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)
Posted: May 26th, 2008 | Author: Andy | Filed under: bbc, ruby | 2 Comments »
Following on from the XMPP stuff, I made a little site that just reads and output what’s playing on BBC radio. It is a toy app at the moment with no real point (and might well fall over), its worth putting on the DAB radio to see the sort of delay it might be experiencing.
mibly.com/radiofall
What is it using I hear you bellow?
- Ruby – well what else?
- xmpp4r gem – for connecting to the xmpp server and parsing the messages
- json gem – for outputting the messages in …. json
- jQuery – to make all those Ajax requests
The next steps are to add some intelligence into the script, interacting with some APIs or something. I have a few ideas, but it depends upon time and if I can get somebody to help with design.
Posted: May 15th, 2008 | Author: Andy | Filed under: bbc, ruby | No Comments »
God bless BBC Radio Labs. They get to build some cool little things including a fun little XMPP server. Its pushing out messages that usually only get seen on the front of DAB radios. I whipped this ruby script together pretty quick (you can tell), but shows how easy you can connect to it.
require 'rubygems'
require 'ruby-growl'
require 'xmpp4r-simple'
username = 'myusername'
password = 'password'
domain = 'hug.hellomatty.com'
im = Jabber::Simple.new("#{username}@#{domain}", password)
im.status(:chat, 'Hello world')
g = Growl.new "localhost", "ruby-growl", ["ruby-growl Notification"], nil, "growl"
i = 0
while true
i+=1
if im.connected? == true
im.presence_updates.each do |friend, old_presence, new_presence|
if new_presence != nil
puts "#{friend.gsub("@#{domain}", '')} #{new_presence}"
g.notify("ruby-growl Notification", friend.gsub("@#{domain}", ''), new_presence)
end
end
else
puts '**************************** disconnected *************************'
im = Jabber::Simple.new("#{username}@#{domain}", password)
im.status(:chat, 'Hello world')
end
sleep(2)
if i == 10
im.reconnect
i = 0
end
end
Here is some sample output.
radio3: Details from bbc.co.uk/radio3 or call 08700 100 300.
1xtra: 1Xtra Dancehall Show - Robbo Ranx. Txt 88111 [network rates apply].
radio4: The World Tonight. Web - bbc.co.uk/news
radio2: Mark Lamarr. Mark presents the Shake, Rattle and Roll Show.
5live: Richard Bacon: Lively and provocative discussion regarding the day's key stories
Now I have no idea what I can do with this (twitter posting is already done to death), so I might have a think about this sort of thing. Be fun if it makes it into production.