Hpricot and woot!

January 13th, 2009 by comment

I know there are several sites for tracking wootoffs on Woot, but I wanted to write my own small program in Ruby. To do this, I used Hpricot by why the lucky stiff.

First, I need my require statements. I’ll need rubygems, since hpricot is a gem, and open-uri to access woot.

require 'rubygems'
require 'hpricot'
require 'open-uri'

Woot has an API that returns XML, so I used Hpricot::XML to parse what comes back.

doc = Hpricot::XML(open("http://www.woot.com/salerss.aspx"))

Now I want to know if it’s a wootoff. If it is, I’ll want to check more frequently. I use the at method to find the element I want, and inner_html to get the text inside that element. The element I’m interested in is woot:wootoff. I’m going to start putting the output into the text variable.

wootoff = doc.at("woot:wootoff").inner_html =~ /true/i
text = wootoff ? "wootoff! ^_^" : "no wootoff v_v"
text << "\n"

Next I want to know what the item is and the price and shipping.

text << doc.at("item > title").inner_html << "\n"
text << doc.at("woot:price").inner_html << " + "
text << doc.at("woot:shipping").inner_html << "\n"

I'll also want to know how much of the item is left, so I know if I need to rush to buy something I want.

percent_gone = doc.at("woot:soldoutpercentage").inner_html
percent_gone = percent_gone.to_f * 100
percent_left = (100 - percent_gone).round
text << "#{percent_left}% Left"

I took all that code and put it into a method, to be looped over every two minutes. I wanted it to print to the screen only if the text changed. This is what the completed program looks like.

#!/usr/bin/ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'

def woot_item
  doc = Hpricot::XML(open("http://www.woot.com/salerss.aspx"))
  wootoff = doc.at("woot:wootoff").inner_html =~ /true/i
  text = wootoff ? "wootoff! ^_^" : "no wootoff v_v"
  text << "\n"
  text << doc.at("item > title").inner_html << "\n"
  text << doc.at("woot:price").inner_html << " + "
  text << doc.at("woot:shipping").inner_html << "\n"
  percent_gone = doc.at("woot:soldoutpercentage").inner_html
  percent_gone = percent_gone.to_f * 100
  percent_left = (100 - percent_gone).round
  text << "#{percent_left}% Left"
end

woot_text = ''
while true
  new_woot_text = woot_item
  if woot_text != new_woot_text
    woot_text = new_woot_text
    puts "*****************************************************"
    puts woot_text
  end
  sleep 120
end

Here is some output from the program.

*****************************************************
no wootoff v_v
Lockjaw Self-Adjusting Locking Pliers - 2 Pack
$9.99 + $5 shipping
100% Left

Of course, this is only a beginning to what you can do. You can have it send a twitter, SMS, email, or any number of things if an item you want is available or a wootoff starts.

Angel

ˆ Back to top

DevChix merchandise

April 8th, 2008 by comment

You can now purchase DevChix merchandise at the DevChix cafepress store. Right now we have shirts, coffee mugs, buttons, and stickers available. :-)

ˆ Back to top

Coworking: a cure for the lonely telecommuter

February 16th, 2007 by comment

There are two types of telecommuters. Those that enjoy spending all of their time alone at home or at coffee shops, and those that really miss interacting with other programmers and geeks in general. I fall into the second category. So what is a lonely telecommuter to do? Enter Coworking. Coworking is a shared space for computer programmers, web designers, graphic designers, etc. to work alongside one another. There is frequently cafe culture involved, and coworking spaces can be in coffee shops or in offices.

A coworking space helps developers network and learn new things. They can be introduced to new hardware, development tools, or methodologies. They might be able to find some work through people they meet there. They can also ask someone a question if they are stuck on a particularly tough problem.
There are advantages to both coworking setups. A coffee shop is cheaper, and it is easier to move around from location to location. It usually costs just the price of a cup of your favorite beverage. The downsides of a coffee shop are that you need to either have a room reserved or have to try and secure a large enough space for the coworkers. It can also be more distracting with all the conversations taking place around the group, unless you’re able to reserve a room.

An office space is more expensive, and you usually have setup costs like furniture, hardware, refrigerator, etc. The upside is that you are surrounded by other people working on something. Sometimes you can also have your own desk to leave a desktop, a second monitor for your laptop, paperwork, pictures of loved ones, or whatever else you might want to have at work. You also don’t have to buy coffee if it isn’t something you want, and sometimes plain black coffee is provided. Plus the cost of sharing the office space is tax deductible.

Even if you fall into the category of the telecommuter that likes working alone, you might consider working in a coworking space. It really can help you meet new people and grow professionally. There may already be a coworking space in your city. If not, you should consider starting one. User groups are a good place to find people interested in working together. There are plenty of coffee shops. So make a post to the user group about meeting together to do work. Who knows, you might end up with coworkers.

ˆ Back to top

New Book: Mongrel by Angel Dobbs-Sciortino

November 21st, 2006 by comment

My book on Mongrel published with O’Reilly is now available for purchase. Mongrel is a web application for Ruby on Rails, more stable than WEBrick, and easier to set up than FCGI to Rails through Apache. You can find it at http://www.oreilly.com/catalog/mongrelpdf/.

ˆ Back to top

cheap research papers