AnsweredAssumed Answered

How to convert a Google Spreadsheet to a .csv file with Python

Question asked by tornado_f5 on Nov 13, 2013
Latest reply on Nov 18, 2013 by tornado_f5
I am working with a google spreadsheet that shows active big foot sightings data.  What I am trying to do is convert the google spreadsheet to a .csv file so that I can then use geoprocessing tools placed in GIS Model Builder to take the .csv file and turn it into a table, and then a point shapefile showing the xy coordinates.  That part is easy.  It's just the first step that has me.  I am receiving a syntax error when I try to run the python script.  Here is what I have:

import csv
import gspread

g = gspread.login('skiesgoinggreen@gmail.com', '???')

docid = "0AgNp9UJ4CX93dHl3RW9GRXJDS3kxaXRJMGNqWmhQWVE"

spreadsheet = g.open_by_key(docid)
for i, worksheet in enumerate(spreadsheet.worksheets()):
    filename = docid + '-worksheet' + str(i) + '.csv'
    with open(filename, 'wb') as f:
        writer = csv.writer(f)
        writer.writerows(worksheet.get_all_values())

Thank you in advance for your help and suggestions.

Outcomes