The Knight In Need of A Kivik: A Twilio Intern’s IKEA Hack

November 27, 2012
Written by
Twilio
Twilion

Twilio Bug Logo
Matt Auerbach

This is a guest post by Matt Auerbach, a Twilio intern alumni, detailing his IKEA hack. Matt is a junior at Boston University studying Computer Science. Check out Matt’s blog, and find him on GitHub.

Once upon a not-too-distant time ago, I was an apprentice Developer Evangelist on Island Twilio, located in NYC. This apprenticeship came to an end, as all good things do, and I left Island Twilio for the familiar land of Boston University, bringing with me all the lessons learned from Twilio.

Still, there are things that a newly minted Twilio Knight can’t overcome, or hack away. In my one final quest, I had to endure shopping for furniture for a new apartment. As is common, or just simply custom, I had to brave the labyrinth known as IKEA to find my furnishing, all without falling prey to the shackles of the Swedish Meatball Mafia.

For those perplexed, IKEA can be a trying tribulation with obstacles at nearly every turn. After being lured in by the smell of sweet meat and vanilla ice cream, I suddenly found myself trapped in the IKEA, with no way out but forward through the maze. The only tools at my disposal: a shopping card and a golf pencil. As I trudged on, I saw in the distance the furniture I had been searching for. Passersby and told me, “The only way to free the furniture of your desire is to scrawl the furniture’s article number down on the card.” They informed me that if I made it to The Warehouse, all would become clear. Article numbers correspond with aisles and rows, and that is where I would find the furniture of my desire.

I survived the journey through the maze, all the way to The Warehouse, and even escaped  the IKEA parking lot where I was entangled in twine. As I reflect on my journey, I find that shopping cards and golf pencils are primitive and tools unbefitting of a Twilio Knight.

As fellow Knights of Twilio have taught me well, I used this knowledge to create an app which banishes the primitive IKEA tools in favor of something more sophisticated. During your journey through IKEA’s maze, you can dispatch text messages via Twilio SMS with article numbers corresponding with the furniture of your desire. When you’ve made your way through the maze, dispatch “done” and it will return the location of your items.

Okay, enough fairy tale stuff. Where’s the code?

You can find the full source for this project on GitHub here.

App.py

Unfortunately, IKEA does not have an API, so there is no easy way to pull product information. To accomplish this task I needed to take advantage of website scraping. Every time someone submits an item number, the program manually searches the site, as if they were human. The file “app.py” accomplishes this feat and there is a snippet of how it works below. First, I use Mechanize to pull the HTML from the IKEA online catalog. Then Mechanize searches for the form called “stocksearch”.

It then enters the user’s input (article number) and the store ID. Mechanize then submits the form. The results page HTML is saved in a local variable. I then use Beautiful Soup to convert the HTML into computer “friendly HTML”. Beautiful Soup scans the page’s CSS for the product location. Beautiful soup also scans for other product information like name, price and the URL.

If the user is existing we return their userid. After an item is submitted we store their item in the database. Once the shopper is done, we traverse the database and send back all their items along with their location.

This project was definitely a little tricky at first. Mainly because it was my first Python App and first time using the Web Scraping tool. This was a great project to learn web scraping from because I really tried to simplify the Mechanize and Beautiful Soup involvement. This was also my first time handling Unicode errors, and boy did those Swedish product names give me trouble.

I hope this app improves IKEA shoppers’ experiences. I know it certainly improved mine! It would be cool to see this app implemented in IKEA Stores.

Checkout the site landing page: http://kivikfinder.com/

If you have any questions or feedback, feel free to Tweet @mauerbac or e-mail me at matthew.s.auerbach@gmail.com.