Cartoon version of meJamie van Dyke

Toward my dreams I persist,
determined, relentless.
Destroy them, you cannot.
For I shall continue,
I shall prevail.
The sands of time,
have expunged my writings.
So let us again set in motion
the teachings,
and share the bollocks.

Jamie van Dyke is proficient in Ruby (and Rails). He teaches, he codes and is working for boxedup.

Twitter + World of Warcraft Announcements
inscribed on 03 May 2009
by Jamie van Dyke

It’s been a while since I posted anything, and I intend to fix that with smaller posts that describe things I’m doing. So let’s start off this new regime with a little post about a tiny script I wrote the other day for my WoW guild. We are now using a twitter account to post scheduled raids and other announcements, and I knocked together a little script that parses our guilds (Enigma on Hellfire) guildomatic site for raids we’ve rostered for later that day, and it posts them to twitter.

I needed to parse some html and for that I use the venerable HPricot gem, and to communicate with Twitter I use the Twitter gem. Here’s the code:

  require 'rubygems'
  require 'twitter'
  require 'hpricot'  
  require 'open-uri'  
  require 'parsedate'

  TWITTER_USERNAME = 'replaceme'
  TWITTER_PASSWORD = 'replaceme'
  # http://enigma-hellfire.guildomatic.com/ is ours
  GUILD_SITE = 'replaceme'

  def get_raids(doc)  
    message = "[RAID REMINDER] "
    curr_date = Time.new
    raids_today = false
    (doc/"tr.today").each do |post|
      raids_today = true
      (post/"td.clickable/a").each do |name|
        unless name.inner_html.include?( 'Roster' ) or name.inner_html.include?( 'roster' )
          message << name.inner_html 
          (post/"td.inviteAtTime").each do |start_time|
            message << " (" << start_time.inner_html << ") | "
          end
        end
      end
    end
    raids_today ? message[0..-3] : nil
  end  
  
  doc = Hpricot(open(GUILD_SITE))  

  httpauth = Twitter::HTTPAuth.new(TWITTER_USERNAME, TWITTER_PASSWORD)
  base = Twitter::Base.new(httpauth)
  message = get_raids(doc)

  if message
    base.update(message)
  else
    base.update("[RAID REMINDER] There are no raids today, take a break, slacker!")
  end

Guildomatic has the raids for today posted in a table cell with a class of ‘today’, which made this much easier. You get the idea from the code.

I’m also cheered up immensely on what 10 minutes of key bashing can output. I run this on my server (hosted by Linode) in a cron job at 12pm every day.

Recent Comments