I've often used Google Trends to see how much things have been searched for (for example the G20) on Google over time - and after the launch of the Guardian Open Platform I realised that I could create something similar - an app that can draw graphs showing how frequently things are written about on guardian.co.uk.

The Guardian Trends app is is now live, and it takes the form of an annotated line graph, with a link on each point that shows a selection of news stories from that time period.

As you can see, the web page is pretty sparse, but there's a fair amount of JavaScript behind the scenes. It uses the Google Visualisation API to describe a mini-spreadsheet and display the graph - all of which is done in the browser. Those lines of JavaScript are written by some Python which is hosted on the Google App Engine. All of which is underpinned by the Open Platform.

So, let's walk through a simplified example to show you what happens when someone uses my app to see how often Barack Obama has been mentioned in the past six months.

Example Part 1: Making the Guardian API request and dealing with the response

The rest of the code extracts the total number of results for 'obama' for that time period, plus the headlines and trail-texts for the three results I've requested (by setting count=3).

So if I run the API call searching for mentions of 'obama' for October 2008, what's returned can be represented like this:

Result count

Results

816

Liveblogging the Obama-McCain town hall debate

Oliver Burkeman's Campaign Diary: A minute-by-minute dispatch

All smiles for Obama in the sunshine state

Eight years after Florida favoured George W Bush, Obama blazes ahead in polls

Obama or McCain: environmental voting records in Congress

Analysis of the voting records of the two presidential hopefuls, with help from our friends at Environment America

Then through calling GetResults once for each monthly window (6 times for this example), and amalgamating all that data, my app puts together a list of lists (a "2D array") in Python:

Search period

Result count

Search description

Results

39722

816

obama - Oct 2008

[3 results]

39753

1110

obama - Nov 2008

[3 results]

39783

490

obama - Dec 2008

[3 results]

39448

949

obama - Jan 2008

[3 results]

39479

655

obama - Feb 2008

[3 results]

39508

639

obama - Mar 2008

[3 results]

Example Part 2: Writing JavaScript with the App Engine

I have to convert this data into a DataTable for the Visualisation API. So, I made some more Python code that iterates over each cell in the table above and outputs the JavaScript needed to describe that cell in a DataTable. The JavaScript output should look like an extended version of this example.

I won't go into detail with the Python here, but for our example case, the JavaScript produced will look like this:

Finally, the App Engine puts this JavaScript in the <head> of the web page, so on loading, the graph will display in the <div> element called chart_div.

When you run the query, you'll see a peak in November coinciding with Barack Obama's election, followed by a smaller peak in January for his inauguration.

I then just had to go that bit further and support plotting more than one line to compare how often different things are mentioned. Putting commas between terms will show you a comparison chart: for example this one compares mentions of Twitter and Facebook.

But what's the point?

I think this app has a few qualities that make it a good tool. It encourages exploration of the Guardian's content through all the links, and if you find a graph interesting, you can copy the URL and send it to anyone. Also, it measures newsworthiness, which is subtly different to how Google Trends measures users' desire for information.

I'm still open to suggestions as to how to take the app further - using tags instead of a free text search, zooming in to a day-by-day view, or even combining it with the New York Times API to compare coverage.

Stephen Elliott develops web-based systems in the City of London, having graduated from Cambridge University. He spends some of his spare time building apps with third party APIs, when he isn't enjoying a foamy pint in an old-man pub with friends. He had thought that the two activities were mutually exclusive, until he discovered an old-man pub with wi-fi. His claim to fame is that he went to school with Lewis Hamilton.