My Peers ↓ Filter:

26 Apr 2012

Data Retrieval and Formatting

Now that I have an API key, I can legally request data from Google Book's. This post will cover how I did that and formatted the data to comply with Harvard reference standards!

Retrieving the Data

Step 1.

The code snippet below shows the string I use to query Google Book's, it must contain my API key, which can be found as a variable at the end. Of course, it also needs to contain the ISBN number for that book which is being queried; this can be found as a variable near the beginning.


Click image to enlarge

Step 2.

Google returns the data in the below format, some of which can be used straight away, some of which can't and needs to be formatted; I've covered this, below.


Click image to enlarge


Formatting the Data

Step 3.

In this snippet, I format the title for Harvard references by checking whether a subtitle exists. Subtitles need to follow a semi-colon after the main title. This function returns one of two possibilities.


Click image to enlarge

Step 4.

This is a slightly more involved function, which splits a single name string between the 'firstname' and 'surname'. It will always return the surname followed by a comma, then a space, which is followed by the initial of the first name.


Click image to enlarge

Step 5.

The date is passed from Google as yyyy-mm-dd, so this function splits the date every hyphen (-) and then returns just the first chunk; the year, in brackets.


Click image to enlarge