Oct. 18, 2010

If you want an easy interface for someone to input regular data, you might like to use a Google Spreadsheet. You can extract the resulting data from the spreadsheet into Python using this code snippet:

import urllib2
import csv

url = GOOGLE_DOC_URL + "&output=csv"
request = urllib2.Request(url)

cookie_handler = urllib2.HTTPCookieProcessor()
redirect_handler = urllib2.HTTPRedirectHandler()
opener = urllib2.build_opener(redirect_handler,cookie_handler)

u = opener.open(request)

data = list(csv.reader(u))

You will need to share the document as "Anyone who has the link can view" because there is no authentication happening here. The variable GOOGLE_DOC_URL should be the URL shown in the "Sharing settings" panel. The final variable 'data' will hold an array of arrays of strings - the spreadsheet values are the strings.

Need software development advice? Book a call with me.