Musings of an anonymous geek

October 31, 2007

Getting at your Google Spreadsheets columns

Filed under: Productivity,Python,Scripting,Technology — m0j0 @ 8:29 am

Regular readers know that I’ve been working on a pet project to build a command line interface to Google Spreadsheets. Basically, I find working in a spreadsheet interface to be clunky and uncomfortable. If I need to put in a new row, I’d rather just be prompted at the CLI for the values I want to put in for each column. Later I’ll add the ability to edit and query my spreadsheet from the command line as well. The nice thing is that I can’t see any reason for this application to be specific to any *particular* spreadsheet, so anyone should be able to use this for whatever Google Spreadsheets document they want 😀

For now, though, in the event that other coders are struggling with their own project, here’s how I finally figured out how to print out the “column: value” pairs for every row in my spreadsheet:

spreadsheet_id = PromptForSpreadsheet(gd_client)
worksheet_id = PromptForWorksheet(gd_client, spreadsheet_id)
columnfeed = ListGetAction(gd_client, spreadsheet_id, worksheet_id)
for attr, val in enumerate(columnfeed.entry):
   for key in val.custom.keys():
      print "%s:   %s" % (key, val.custom[key].text)
   print "\n"

I had initially hit a bit of a snag in getting to this point, because it’s not made clear in the Google Documentation how to reference your columns. They *do* tell you how to print “val.content.text”, but that prints all of the column:value combinations together in one big, long string. You can’t even parse that, because nothing is quoted, and column data can include anything you might use as a delimiter. I finally got around to looking at this again today, and with the help of IDLE (which I’ve now accepted as my saviour) finally poked and prodded ‘val’ until it spit out something close to what I was looking for.With that task out of the way, it should be easy enough to start performing write operations, and I believe I remember query operations being documented by Google separately – so hopefully this will go more quickly now.Wish me luck!

1 Comment »

  1. I wish you luck, Brian, and what’s more (since you mention ‘val’ and IDLE):

    – check out the article titled something like “A guide to Python Introspection” by Patrick O’Brien on IBM developerWorks,

    and

    – the inspect module in the Python standard library.

    Both may help.

    – Vasudev Ram
    http://www.dancingbison.com

    Comment by vasudevram — November 1, 2007 @ 5:48 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

Create a free website or blog at WordPress.com.