Wikipedia Time Machine (Part 2)

Part 1 introduced the concept of the Wikipedia Time Machine, a tool that will allow us to browse the Wikipedia as of a particular time and date, so as to avoid learning results of soccer games before we have a chance to watch them via DVR. I couldn't find any existing tools, so I started looking into writing it myself. I found a mechanism for specifying a page version in the URL, but I can't specify the version as a timestamp. So how do I translate a timestamp into a version? There must be a Wikipedia API, right? Back to Google!

And, indeed there is a Wikipedia API.  And one of the actions "query", allows you to get revision properties, and it looks like we can specify a timestamp and get the revision back.  This URL seems to do what we need:

http://en.wikipedia.org/w/api.php?action=query&titles=San_Francisco&prop=revisions&rvprop=timestamp|ids&rvlimit=1&rvstart=2014-06-21T20:00:00Z&format=jsonfm

It returns:

{
    "query-continue": {
        "revisions": {
            "rvcontinue": 613845875
        }
    },
    "query": {
        "normalized": [
            {
                "from": "San_Francisco",
                "to": "San Francisco"
            }
        ],
        "pages": {
            "49728": {
                "pageid": 49728,
                "ns": 0,
                "title": "San Francisco",
                "revisions": [
                    {
                        "revid": 613847076,
                        "parentid": 613845875,
                        "timestamp": "2014-06-21T19:59:58Z"
                    }
                ]
            }
        }
    }
}

Check out the "revisions" list. There's that revid we wanted.  So, using what we learned in Part 1, let's see if we can get the version we want.

I'll be damned. It worked! Take a look at the page. It even warns us at the top that we have an old revision, and it gives us the last changed date of the page. Nice.

Alright, so how do we build a tool to do this? That'll be Part 3.