Data Visualisation: Getting Your Untappd Checkins

It goes without saying really, that if you want to visualise data, you need some data. As I mentioned in my last post, I have an Untappd API key, so have access to a data set that I’m quite interested in exploring. The following code isn’t an all singing, all dancing solution to getting hold of your Untappd checkins, it’s far too rough and ready for that. It does serve as a starting point though, we need data, this Python script gets us that data, we can come back later and improve it.

This isn’t the first Python script I’ve written, but it is the longest and most complicated, which gives an idea of just how much I’ve played with Python. To enable it to run you need to modify the script with your Untappd API access keys and the username of the Untappd user you want to get checkins for. You’ll also need a MongoDB instance, if it’s not running on the default port, then you’ll also need to modify the bit that creates the MongoDB client so it knows which port to use etc.

from pymongo import MongoClient
import requests
# Your Untappd details...
untappd_user = ''
untappd_client_id = ''
untappd_client_secret = ''
# Connect to the local MongoDB instance...
client = MongoClient()
db = client[untappd_user]
# Does the user have any checkins already...?
if 'checkins' in db.collection_names():
print 'Dropping previously slurped checkins...'
db.drop_collection('checkins')
# Create a new collection so we can slurp checkins into it...
checkins = db.create_collection('checkins')
# We don't have any checkin info at the moment, so don't set the checkin max_id
max_id = None
# Connect to Untappd and pull down some checkins...
while True:
# These are the parameters we send every time...
parameters = {'client_id': untappd_client_id, 'client_secret': untappd_client_secret, 'limit': 50}
# Each time we go round the loop apply the max_id...
if max_id != None:
parameters['max_id'] = max_id
# Get some checkins...
r = requests.get('http://api.untappd.com/v4/user/checkins/' + untappd_user, params=parameters)
json = r.json()
if json['meta']['code'] == 200:
# Update the max_id...
max_id = json['response']['pagination']['max_id']
# Load the checkins into mongo...
checkins.insert(json['response']['checkins']['items'])
# If we didn't get 50 checkins then we're done, so break out...
count = json['response']['checkins']['count']
print "Inserting %i checkins into mongo..." % count
if count < 50:
break
else:
print json['meta']['error_detail']
break
print "%s now has %i Untappd checkins in MongoDB..." % (untappd_user, checkins.count())
view raw untappd.py hosted with ❤ by GitHub

So what could we improve on? The main thing would be to not throw away all the checkins we’ve already managed to add to the MongoDB each time the script is run, it should really just get those checkins that the user has made since the last run of the script. There is also no error handling, so if you run out of Untappd API calls, you’re limited to 100 per hour, it doesn’t handle the error response and inform you.

You can find all the code of this series of blogs in one of my GitHub repositories.

OpenELEC

The HDMI cables and SD cards I ordered via Amazon, were waiting for me when I got home on Friday after work. So I spent some of Saturday morning trying to get OpenELEC up and running on my Raspberry Pi, with various levels of success.

Earlier in the week I cloned the OpenELEC github repository and compiled the source, before installing it onto the SD card I normally use in my Nikon P6000. I followed the instructions on this page of the OpenELEC wiki and it appeared to all go to plan. A couple of corrections needed to be made in the Installing OpenELEC to the SD Card section, as the build put certain files in a different place to that specified. Instead of copying the files from:

$ sudo cp build.OpenELEC-RPi.arm-devel/bcm2835-driver-*/boot/arm128_start.elf /media/System/start.elf
$ sudo cp build.OpenELEC-RPi.arm-devel/bcm2835-driver-*/boot/bootcode.bin /media/System/
$ sudo cp build.OpenELEC-RPi.arm-devel/bcm2835-driver-*/boot/loader.bin /media/System/

They were in the bcm2835-bootloader-* folder, not the bcm2835-driver-* folder, so I copied them with:

$ sudo cp build.OpenELEC-RPi.arm-devel/bcm2835-bootloader-*/arm128_start.elf /media/System/start.elf
$ sudo cp build.OpenELEC-RPi.arm-devel/bcm2835-bootloader-*/bootcode.bin /media/System/
$ sudo cp build.OpenELEC-RPi.arm-devel/bcm2835-bootloader-*/loader.bin /media/System/

After a bit of faffing with my TV and AV equipment, I finally managed to get a picture displaying on the TV, but as you can see from the image at the top of this post, all I got was an error message. Rather than break out the laptop to edit the cmdline.txt file and spend a while trying to get the partition name correct, I just downloaded one of the nightly builds and ran the create_sdcard utility. This produced a working SD card and I was able to boot straight into XBMC, all in all a much easier and less time consuming option.

github

I’ve finally succumbed and created a github account. I have no idea how to use github or git, other than cloning a repository. I have some ideas of what to put on there, I’m just not sure how I should lay it all out yet. Suppose I should really dust off a couple of old projects that have fallen by the wayside and finish them off.