One line of code

How I built an API for the London 2012 Olympics with one line of code.

almost 4 years ago - 4 min read

In 2012, I built an app for the London Olympics. I'd seen the official app in the months leading up to the games and decided I could do better, so I set to work. I wasn't looking to profit from it, I just wanted to learn how to build an app.

In one section was news and in another was a global medal table. These had to be kept updated in real time. Back then I wasn't as proficient in cloud services as I am now, so I was looking for a simple solution. There was no official medal list API. I needed a way of obtaining, storing and serving this data for free. I was also worried about hosting costs - afterall, this is one of the biggest world events, what if my app became popular and struggled to deliver content.

I decided that the easiest thing to do was host a csv file. I would keep that updated and it would load into the app on every pull-to-refresh. But how could I keep it updated? And where could I host it? I thought about watching the games religiously and inputting all the data by hand, but decided to just steal a medal table from Wikipedia instead. Thanks Wikipedia moderators!

I loaded up Google Sheets and typed this into a cell:

=IMPORTHTML("https://en.wikipedia.org/wiki/2012_Summer_Olympics_medal_table", "table", 4)

And out popped the medal table…

+───────+────────────────+───────+─────────+─────────+────────+
| Rank  | NOC            | Gold  | Silver  | Bronze  | Total  |
+───────+────────────────+───────+─────────+─────────+────────+
| 1     | United States  | 47    | 27      | 30      | 104    |
| 2     | China          | 38    | 31      | 22      | 91     |
| 3     | Great Britain  | 29    | 18      | 18      | 65     |
| 4     | Russia         | 19    | 21      | 27      | 67     |
| 5     | South Korea    | 13    | 9       | 8       | 30     |
| 6     | Germany        | 11    | 20      | 13      | 44     |
| 7     | France         | 11    | 11      | 13      | 35     |
| 8     | Australia      | 8     | 15      | 12      | 35     |
| 9     | Italy          | 8     | 9       | 11      | 28     |
| 10    | Hungary        | 8     | 4       | 6       | 18     |
| ...   |                |       |         |         |        |
+───────+────────────────+───────+─────────+─────────+────────+

Bingo!

All I had to do was Share > Publish to web > as .csv and hey presto, here was my API.

And better still, there was an option to Automatically republish when changes are made which would poll the website every 5 minutes and update the CSV accordingly.

I pointed it at a few websites - BBC Sport, The Guardian, Wikipedia etc… So if markup broke on one website, it would default to the next one in line.

I did the same for the news; pointing at Google's own news site for tagged olympic news and then I launched the app with a few weeks to go before the opening ceremony.

I had tickets to the first day of the olympics and as I queued to get in with my friends, I pulled my phone out of my pocket, opened the app and pulled to refresh. It worked like a charm - all the way through the olympics. No hosting fees, no worries.

Actually looks like it may be easier to use than the official app

- The Guardian

The app had a reasonable amount of downloads (~10k), the API never went down, and it gave me the confidence to start building more apps and services.

Building digital services these days can be incredibly complicated. But I often think about this one line of code that instantly provided an API. It taught me to look for the simplest, smartest route - the fewer moving parts, the fewer things can break.