A Peek Behind How an API Brought an XKCD Cartoon to Life

Mike Melanson, November 18th, 2010

Trade MeSo far, Paul Hunkin’s bot has bought him two sets of camera batteries, a gift bag, a USB extension cord, a 1955 stamped envelope and a smattering of other items. Hunkin, you see, decided to bring an XKCD cartoon to life by programming a bot that automatically purchases cheap items using a New Zealand auction site’s Trade Me API… because packages are exciting.

Hunkin explains the inner workings of the bot and the idea behind it on his blog. “I happened to stumble across this old comic from XKCD,” he writes. “Google didn’t reveal anyone doing this already, and after asking a few people, the general opinion was that doing this was a terrible idea that would inevitably end badly. So obviously I had to do it.”

Using the TradeMe API and writing using Python and python-oauth2, the script runs once a day and has a one in three chance of buying an item. The script gains $1 every day, so it can slowly accumulate savings and purchase “some (slightly) more expensive items”. Hunkin explained the method he uses to select items:

  • It has a bunch of top-level categories it looks in.
  • For each of these categories, it searches for the term “Free shipping”, specifying both pay-now and buy-now, sorting by newest listings, with a maximum of 100 items returned per category.
  • For each of these items, it filters on buy-now price. It tries to spend at least 50% of its savings.
  • For each of the surviving items, it looks up the individual auction details to find its shipping information so it can filter on free shipping. Despite searching for the term ‘free shipping’ to start, only a small number of items have this.
  • At this point I have a list of items that match the price requirements, and can be bought with a credit card buy-now.
  • I then sort this list by ‘rarity’ – doing a search for the item title, and finding the item that returns theleast results. As the objective here is to buy strange and esoteric things, rarity is preferred.
  • Finally I buy the rarest item and subtract its cost from the bots savings.

After receiving his second set of watch batteries, Hunkin made some improvments, including automatic bidding on auctions, hourly increments to its spending limit and a “limited understanding of shipping information”. In addition, it checks to make sure it hasn’t bought the same item before.

Even a cursory look at the comments on Hacker News show the potential for automated auction-site scripts. From automatically purchasing and selling items on margin to a counter-bot that submits cheap items for Hunkin’s bot to buy.

To keep up with Hunkin’s bot and it’s semi-daily purchases, you can follow it on Twitter, Facebook and on his blog.

Tags: Shopping
Both comments and pings are currently closed.

9 Responses to “A Peek Behind How an API Brought an XKCD Cartoon to Life”

November 18th, 2010
at 7:41 am
Comment by: John Lancia


November 18th, 2010
at 7:47 am
Comment by: Mike Melanson

Indeed. Peek not peak. Not sure how that got there. :) Thanks!

November 18th, 2010
at 8:38 am
Comment by: Denver Dave

Wow…that’s AWESOME!!!!! I laughed, I fell into a jealous fit, then I laughed again!

November 18th, 2010
at 10:43 am
Comment by: bieh.net » xkcdbot news roundup

[...] programmableweb.com: A peek behind how an API brought an XKCD cartoon to life [...]

November 18th, 2010
at 12:07 pm
Comment by: Adam DuVander

Blame me on the typo. And, perhaps, late night editing.

November 19th, 2010
at 12:34 am
Comment by: Stephen Fleming

Such this information is really attractive and also awesome…. so thanks for this information… but now days i get the new buy scripts from the online…

November 19th, 2010
at 8:45 pm
Comment by: Hack of the Day: Kiwi Uses API to Buy Random Stuff Everyday : Home Jobs

[...] Hat tip: Programmable web [...]

November 22nd, 2010
at 12:35 am
Comment by: API måndag – offentlig data, Disqus, Facebook och meningslösa mashups « Mashup.se

[...] betydligt coolare mashup är utvecklat av en Nya Zeeländare och handlar automatiskt saker på den lokala auktionssajten [...]

November 26th, 2010
at 2:32 am
Comment by: Stephen Fleming

I am impress for this site information… i a always use this information for my new website…. so thanks for the sharing this information about how to buy scripts for my new project….

Follow the PW team on Twitter

APIs, mashups and code. Because the world's your programmable oyster.

John Musser
Founder, ProgrammableWeb

Adam DuVander
Executive Editor, ProgrammableWeb. Author, Map Scripting 101. Lover, APIs.