Building an Exercise and Weight Display: Part 1

[I’ve called this Part 1. Let’s see if I get around to writing parts 2–4.]

While doing some overplanning in the last few weeks of the year, I built a few text files and spreadsheets. In the process, I decided that some sort of display would be worthwhile for keeping track of a few goals that I had developed. I thought about Dashboard widgets, but they seem to be waning. And then I thought about NerdTool/GeekTool, but those never worked very well for me when switching monitor resolutions, which I do often. And then a friend mentioned Übersicht, which I didn’t think I had heard of, but Brett Terpstra has written a couple of widgets. So, I’ve probably at least heard of it.

So, I played with some of the widgets from the gallery, and developed the beginnings of the heads up display that I wanted. But, one of the things I wanted was a way to track weight and exercise. I’ve been tracking my running for the last few years in RunKeeper, and I’ve been tracking my weight, off and on, in Weighbot. So, the first question was how to get the data out.

Weighbot presented a problem. It is mostly an iOS app, although it has a cloud backup service. The cloud backup service will let you download all your data in a CSV file from a website. This could probably be automated. But, my tests suggested that Weighbot usually did a backup immediately upon app launch. My usual usage pattern is that once a day I launch the app, enter my weight, and then close the app. The backup on launch, though, meant that the data set I downloaded was always missing today’s data point, unless I forced an additional backup. Then I realized, though, that RunKeeper could also track weight. I put a couple weeks worth of data points in, and I was off to the races.

RunKeeper has an API called HealthGraph that lets other apps access their data. I assumed that access to this API would be simple, like for Flickr or Forecast.io. But it’s a little more involved. First, you register, and they give you a Client ID and a Client Secret. You then use the Client ID to get RunKeeper to generate a Code. You then use the Client ID, Client Secret, and Code to generate an Access Token, which finally lets you access the data. Figuring all this out and making it work seamlessly is probably worthwhile if you are building an app for the masses, but it was quite a lot of trouble for a one-off data display. Luckily, this blog post walks you through the steps and provides the necessary snippets of code.

Then, I was off to the races. Starting by stealing some API access code from Dr. Drang, I used my new Access Token to create some Python code that downloads my run data and my weight data. Basically, you request a URL with a couple extra headers (including the Access Token) in the HTTP request, and you get back JSON blobs of data. I then wrote code that processed those blobs into a graph and extracted the bits of raw data that I wanted to display. At that point, I needed to get the raw data over to Übersicht to format for display. I puzzled for a bit about how to do this, and I wound up with an obvious solution—another JSON blob. Since Übersicht uses a JavaScript-related language called CoffeeScript, I assumed that processing the JSON would be straightforward, and it was.

Here’s the code that downloads the necessary JSON blobs. It requires a bit of explanation. First, it gets the Access Token from a file called .runkeeper that I keep in my home directory. Then, it makes an initial call to the RunKeeper API to get a JSON blob of user information. In fact, with the exception of a User ID, this blob contains almost no actual user information. What it contains, instead, are pointers to the URLs to use to obtain the desired JSON blobs. In fact, these seem to be static strings, but the API documentation insists that they should not be hardcoded. Thus, the next two calls to the RunKeeper API use the information from the user blob to request the fitness_activities blob and the weight blob.

#!/usr/bin/python
# coding=utf-8

from __future__ import division
from __future__ import unicode_literals
import json
import urllib2
from os import environ

# Get my Runkeeper Access Token
try:
  with open(environ['HOME'] + '/.runkeeper') as rcfile:
    for line in rcfile:
      k, v = line.split(':')
      if k.strip() == 'access_token':
        AccessToken = v.strip()
except (IOError, NameError):
  print "Failed to get Access Token"
  exit()

# Get the user from Runkeeper
try:
  userReq = urllib2.Request('http://api.runkeeper.com/user') 
  userReq.add_header('Authorization', 'Bearer ' + AccessToken) 
  userReq.add_header('Accept', 'application/vnd.com.runkeeper.User+json')
  userJsonString = urllib2.urlopen(userReq).read()
  user = json.loads(userJsonString);
except (IOError, ValueError):
  print "Connection failure for user."
  exit()

# Get the fitness activities from Runkeeper
try:
  fitnessReq = urllib2.Request('http://api.runkeeper.com' + user['fitness_activities']) 
  fitnessReq.add_header('Authorization', 'Bearer ' + AccessToken) 
  fitnessReq.add_header('Accept', 'application/vnd.com.runkeeper.FitnessActivityFeed+json')
  fitnessJsonString = urllib2.urlopen(fitnessReq).read()
  fitness = json.loads(fitnessJsonString);
except (IOError, ValueError):
  print "Connection failure for fitness activities."
  exit()

# Get the weight from Runkeeper
try:
  weightReq = urllib2.Request('http://api.runkeeper.com' + user['weight']) 
  weightReq.add_header('Authorization', 'Bearer ' + AccessToken) 
  weightReq.add_header('Accept', 'application/vnd.com.runkeeper.WeightSetFeed+json')
  weightJsonString = urllib2.urlopen(weightReq).read()
  weight = json.loads(weightJsonString);
except (IOError, ValueError):
  print "Connection failure for weight data."
  exit()

Each call to ‘json.loads()’ parses a JSON blob and turns it into a Python dictionary. The structure of these dictionaries (JavaScript Objects) is explained in the HealthGraph API documentation. Here is the documentation of the fitness_activities blob, and here is the documentation for the weight blob. There is no real error checking, and your mileage may vary, etc.

It’s been a fun little project. If I were to write a second part of this blog post, it would be on extracting the running data for display (and retrieving my training plan from a text file for display, as well). If I were to write a third part, it would be on extracting the weight data, computing my weight goals, and creating a plot of both the data and the goals with Matplotlib. And if I were to write a fourth part, it would be on writing the HTML, CoffeeScript, and CSS to display everything as an Übersicht widget, which was by far the most painful part of the whole process. But I’m a professor, so I may leave those tasks as an exercise for the reader.

Bits and Pieces

  • Blogging 101 wasn’t for me. I sortof knew that it was for new bloggers, but I thought that I could make it work. I couldn’t or didn’t. The assignments didn’t appeal to me. Besides, November (and the first half of December) is a busy time in academia. So, it didn’t really happen. So it goes.

  • But, I’ve given up social media for Advent. So, maybe while I’m absent from Twitter I’ll blog more. Maybe. Do people give things up for Advent? Not that I know of. But I have to take periodic breaks from social media or it starts to make me crazy. Advent and Lent seemed like one way to do it; both are seasons of waiting and preparation.

  • If you miss me that much, though, I’ve decided that Instagram doesn’t count. (Mostly because I follow only a few people on Instagram and the volume of posts is light.) Will I blog more often or Instagram more often? Yes. Maybe.

  • Every December for the last several years I’ve hit Instapaper zero. It happened by accident the first time or two—Winter Break is conducive to reading all the things—but for the last couple of years it has been intentional. And as I started making my way through my queue this year, I finally read Ta-Nehisi Coates’s piece on reparations from last June. Wow. There is so much about the history of racism in the United States that I was never taught. The piece was widely lauded, so I’m late to the party, but it’s probably the best thing I’ve read this year.

  • On a lighter note, I’m a long time fan of Merlin Mann, and hence a long time listener to his podcast with Dan Benjamin, Back to Work. If I may be so bold, it is a lot of nonsense punctuated by moments of brilliance. And in the most recent episode, a little after 1:27, Merlin says, “The problem is you still have hope about email. That is hell. Hell is believing that there is hope in email. The only thing that can actually help you is to realize that it is completely hopeless.” My name is Allen, and I have an email problem.

  • And today, after finishing up that episode, I was listening to this fantastic interview of Ira Glass by Alec Baldwin. So, so good. I don’t listen to Alec Baldwin’s show very often, but maybe I should. (I wrote a whole post about his interview of Billy Joel back in 2012.)

Here We Blog Again

Lots of people are talking about blogging again, from well-known folks that don’t need a link from me to my friend Steve. And a Twitter conversation yesterday about the subject with local bloggers Alice and John led to this post. So, I signed up for Blogging 101 this month. Not because I need the training, but because I surely need the encouragement.

The first assignment is to post about “who I am and why I’m here”. I’m Allen. I started blogging in October 2001—you can see the archives down the right side there. I haven’t always blogged consistently, to say the least—you can see that down the right hand side, too.

A lot has changed for me since October 2001: I finished my Ph.D., got a tenure track job, and got tenured and promoted. Along with that tenure track job, I moved to Southwest Virginia and bought my first house with my lovely wife, Becky; this summer, we sold that house and bought a different one across town. We did that in part because it isn’t just the two of us like it was back then; now, there are three more: Charlie (8), Megan (6), and Noah (4). We lived in Ireland for a year, too, all five of us, and it was fantastic. So, I guess I’ve been busy.

But I’m back to blogging because I need a place online to call my own. This blog has always been about precisely whatever I feel like writing about. It’s not a professional blog; it’s a personal one. It will be about my hobbies, my fascinations, my family, and my free-floating opinions. I admire bloggers who cross professional lines and write amazing blogs about their professional expertise, but so far, I don’t seem to be one of them. If that changes, you’ll be the first to know.

I tweeted on Friday that “I work with some fantastically generous, brilliant people.” The same could be said for my friends, online and off. I hope this blog keeps me in touch with those friends, reconnects me with old ones, and helps me make some new ones. Is that too much to ask? I don’t think so.

A Paean to a New Favorite: Bell X1

I’ll be the first to confess that I have eclectic musical tastes. (A common feature is that I almost exclusively like singer-songwriters, though.) So, standard disclaimers apply. Lately, though, I’ve been listening to Bell X1 a lot, though, and I wanted to share.

Bell X1 is a band from Dublin, Ireland. They popped up on my radar last Fall, a few months after we returned to the states. I don’t even remember how I first came across them. But I liked the bit that I heard, and their Wikipedia page claimed they were the second most popular Irish band in Ireland after U2, which seemed like an interesting (if impossible to measure or verify) factoid. So, I bought their double live album, Field Recordings, released in 2012.

I played it often and continued to like it. Months later, I found myself on the band’s website just after they’d announced their 2014 US Tour. One of the tour dates was to bring them to Maryland, where my in-laws live. So, I hatched the scheme of making a weekend of the concert, leaving the kids with their grandparents, and I bought a pair of tickets.

Shortly after buying the tickets, I bought their latest studio album, Chop Chop. I listened to it several times, but it didn’t really click for me. I mentioned to a friend in Ireland that we were going to see them, and he shrugged (virtually) but said they were probably good live.

“Good live” was a dramatic understatement, though. They were fantastic live, particularly in an intimate venue. The musicianship, as the band members moved effortlessly from instrument to instrument was astounding, and, though they have a clear lead singer, they were all great vocalists, too. The lyrics were a bit easier to understand live, too, and I was moved by them. Not only that, but they played several songs from Chop Chop, and it really made those songs come alive for me.

My new favorite from Chop Chop is probably “Feint Praise”. I like the overall message of the song, about the bankruptcy of conflict avoidance, and I love the description that faint praise has a “bitter aftertaste, like rust.” But I also just love the almost-non-sequiter in the bridge, because it’s just dripping with Irishness: “You must never squeeze the teabag // Leave it alone // What did it ever do to you?”

But the last song on Chop Chop has also really grown on me since the concert. It’s an apocalyptic song called “The End is Nigh”, but it’s less about the end itself than about the people we’d choose to be with in the darkest of times. We saw Bell X1 on September 12, and the band had played in New York City the night before. They mentioned that they didn’t play “The End is Nigh” though, because it seemed too “close to the bone” for that day. Some lyrical goodness from that one: “And flailing like a landed fish // Trying to get back to before his day went awry.” I find that image both funny and deeply resonant.

But this post was actually prompted by the video below, which the band tweeted today. It’s from that September 11 show in New York City. They played the same song in Annapolis the next night as their first encore. I don’t think it gives you a great feel for the band’s music, because they’re really a “Pop/Rock Combo” (their description, in another song) that mostly plays original music, and this is an acoustic cover. But it gives you a feel for their incredible musical talent, even if the live audio recording leaves a bit to be desired. It’s a song called “She’s a Mystery to Me” written by Bono and The Edge for Roy Orbison, who popularized it.

Bell X1 “She’s a Mystery To Me” from Patrick Glennon on Vimeo.

This afternoon, I also learned that the lead singer of Bell X1, Paul Noonan (on the right in the video), has a computer engineering degree from Trinity College Dublin. So, I guess that by itself explains just about everything about my newfound love for a random band from Dublin.

Coffee Heresy

You can make great coffee at home or work. Lots of people have written about how to do it. Maybe later, I’ll tell you how I do it. But for now, here’s a great article. If you want, you can skip the geeky back story in that article and jump straight to the six principles. They are simple. They are solid. You are welcome.

Let me make an observation, though: The equipment required to make a great cup of coffee is relatively inexpensive. You’re going to need a conical burr grinder, but you can get a Hario Mini Mill for \$29 (and I’ve seen them for less). You have several choices for brewing equipment, but the main options are less than \$25. You’ll also need a way to heat water, but you probably have one of those already.

But once you get into it, there’s a world of stuff to learn about growing regions and farms, about roasting, and about your personal preferences. I haven’t scratched the surface of most of this stuff on my own coffee journey. I just know when it tastes good, and I appreciate that it is an agricultural product handled with love and care by my favorite local roaster.

You cannot make great espresso at home or work. At least, you can’t without a lot more time, effort, and money than you are probably willing to invest. In terms of money, they used to say that a good espresso machine would set you back at least \$2000. I’ve been watching these guys since their Kickstarter went live, and from everything I hear they make an amazing machine, breaking new ground in “inexpensive” home espresso, for \$800.1

Once you get a decent machine, you’re going to need some training. Seriously, if you want to do this right, you need barista training, and you need to get it from someone good. And then you’re going to have to practice, a lot. But even then, you’re probably not going to pull a perfect shot first thing every morning. How do I know? Because I regularly see great baristas who have pulled thousands of shots throw them away when they don’t come out right. And I’ve been served lousy espresso by baristas that ought to know better. You have to get the grind dialed in, the portafilter tamped just so, and then you have to get the temperature, pressure, and timing right. And then, for many espresso drinks you have to learn to properly steam milk, and keep things clean in the process.

I like espresso drinks. My favorite drink is the latte, but a good espresso shot can also be divine. But take my advice: Learn to make good coffee at home, and find a great local coffee shop to make your espresso drinks. Treat yourself, and think of all the time and money you are saving. You can buy me a latte to thank me.

Here comes the heresy: If, even after reading my advice, you absolutely must have espresso at home or work, Nespresso is probably the way to go. You can get a Nespresso machine for under \$200. The capsules aren’t cheap, but neither are they particularly dear (about \$0.65 each). They’ll give you a consistent, espresso-like experience, no skill or training required. I used them at work in Ireland, because there was a machine at the office.2 Nespresso is served in Michelin-starred restaurants and sometimes beats espresso in taste tests. I think those taste tests are flawed (and there are others that contradict them), but I think they make my point, nevertheless. The likelihood that you are going to make better home espresso than a Nespresso machine without a substantial investment of time, effort, and money is nil. I will add, though, that I have never used their milk frothing contraption; you’re on your own, there.

IMG_0014

Anyway, that’s my advice: Learn to make great coffee at home and work. Buy your espresso drinks from your friendly neighborhood barista and leave a tip. If you won’t take that advice, though, then Nespresso might be your ticket.


  1. One of the guys who started the company was a VT engineering graduate student, so I have followed the project from the start. Despite everything I say here, I sortof wish I had gotten one of their machines for \$200 or \$300 during the Kickstarter. Back in those halcyon days they thought their machine would retail for \$400. 

  2. I did, in fact, bring a grinder and an Aeropress to Ireland with us to make the great coffee described at the beginning of this post. But I kept and used those at home. 

A Stroll Through Irish Literature

I want to blog again, but I can’t seem to find the hook, or the time. Nevertheless, here is a post.

Starting in the Spring, while we were still in Ireland, I read some Irish literature. I started with Strumpet City because it was Dublin’s One City One Book selection for 2013. Then I proceeded to read some Yeats (a couple of collections of poetry) and to reread some Oscar Wilde (The Importance of Being Earnest, which I totally loved when I encountered in high school, and something else which now escapes me). And then I read Dubliners, by James Joyce, which is quite accessible and quite enjoyable, before being cajoled into reading Ulysses.1 And I may have read some other things that I have now forgotten.

But the last thing that I read in this recent stroll through Irish literature was TransAtlantic by Colum McCann. It was long listed (but not short listed) for the Booker Prize this year, and it was wonderful. I’ve already added Let the Great World Spin to my short list.2

In any case, I have said remarkably little, to almost anyone, about the situation with Northern Ireland.3 Which is probably appropriate, given how little I really know about this centuries-old struggle. Nevertheless, I thought this passage from TransAtlantic was full of insight. I’m quoting Colum McCann here, but these are thoughts that he puts in the head of former US Senator George J. Mitchell (a character in the novel, parts of which are historical), around the time of the signing of the Good Friday Agreement in 1998. McCann interviewed Mitchell extensively in writing the novel, I understand, but obviously we can’t hold Mitchell responsible for McCann’s depictions of his thoughts.

[The British] are a tough, intransigent lot, though they have softened a good deal in the past year or so. Embarrassed by what they have done for centuries in Ireland. Ready to leave. To hightail it out of there. They would wipe their hands clean in an instant, if only they didn’t have to do it in front of the world. They seem stunned that Northern Ireland somehow exists. How did they possibly ever believe that the country could have been good for them? What it all came down to was pride. Pride in the rise, and pride in the fall. They want to be able to leave with a measure of dignity. Tally-ho. Ta-ra. Voyeurs to their own experience. Living at an angle to the moment. And the Irish, down south, with almost the exact opposite dilemma. Embarrassed by the fact that it was taken away. Centuries of desire. Like the longing for a married woman. And now suddenly she is there, within your grasp, and you’re not quite sure whether you want her at all. Second thoughts. Other dowries. The mildew in the room where the past is stored. The Unionists, the Nationalists, the Loyalists, the Republicans, the Planters, the Gaels. Their endless gallery of themselves. Room after room. Painting after painting. Men on tall horses. Flags into battle. Sieges and riverbanks. The alphabet soup of the terrorists.


  1. Yes. I read Ulysses. I’m glad that I did, but it was hard, and I wouldn’t exactly recommend it. It contains moments of absolute brilliance. But it requires either the patience for careful study, which I do not possess, or the willingness to plow on even when one feels completely adrift having completely lost sight of the plot, which I, apparently, do possess. 

  2. I have two lists. A long list of things that I would like to read but may never get around to. And a short list, resembling a plan, of things that I reasonably expect to read in the next few months. 

  3. I can’t believe that I’m about to explain this, but a bafflingly large proportion of otherwise educated Americans seem unaware of even these basic facts. The island of Ireland, to the West of the island of Great Britain, has been divided into 32 counties for some centuries (apparently since shortly after the Norman invasion of Ireland in the 1100s). Of those 32 counties, 26 form the Republic of Ireland, an independent nation which has existed since 1922. (The Republic of Ireland was preceded by the Irish Republic, a revolutionary state that declared its independence from the United Kingdom in 1919.) Northern Ireland consists of 6 counties (in the North, naturally) that remain part of the United Kingdom and was created when Ireland was partitioned by an act of the British parliament in 1921. This partitioning of Ireland remains contentious to this day, but disputes have largely remained peaceful since the signing of the Good Friday Agreement in 1998, granting Northern Ireland some measure of self-governance and self-determination.