Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

I'd like to be able to call a script, which will add a row to a Google Docs spreadsheet, and manage stuff like user login. For example,

 gdocs_addrow --id <doc-id> name="John Doe" age="31"

I know there are nice Python APIs but I want to work at an even higher level.

My use case is that I want to make a script that uploads unit test results to a shared document.

share|improve this question

migrated from superuser.com Aug 13 '11 at 0:16

This question came from our site for computer enthusiasts and power users.

    
This post might help out: webapps.stackexchange.com/a/48417/29140 –  Jacob Jan Tuinstra Aug 1 at 18:34

2 Answers 2

I wrote such a tool. It's written in python, but designed to be used from the command line. Have a look at logss. I've been using it to upload daily stats from a cron job.

Beware: I've not got great python installation skills, so running it is a little ad-hoc.

share|improve this answer

If you want a row for each unit test, and for the command to either add a row or update an existing row then you need to have a key column. I've written&used this python library for similar problems: http://sheetsync.readthedocs.org/en/latest/

Once you've installed it with:

pip install sheetsync

You could write a gdocs_addrow.py script like so:

import sys,sheetsync,argparse

def parse_cmd_line():
    parser = argparse.ArgumentParser()
    parser.add_argument("--id", metavar="GOOGLESHEET_KEY",required=True)
    parser.add_argument("--key", metavar="KEY_COLUMN_NAME",required=True)
    parser.add_argument("--sheet", metavar="WORKSHEET_NAME",default="Sheet1")
    parser.add_argument('fieldvals', metavar='FIELD=VALUE', nargs='+',
                       help="A list of FIELD=VALUE arguments")
    opts = parser.parse_args()
    opts.fieldvalue_dict = dict([fv.split("=") for fv in opts.fieldvals])
    if not opts.fieldvalue_dict.has_key(opts.key):
        print "'%s' specified as the key field, but not found in field=value list" %     opts.key
        sys.exit()
    opts.key_value = opts.fieldvalue_dict[opts.key]
    return opts

if __name__ == '__main__':
    opts = parse_cmd_line()
    target = sheetsync.Sheet(username="<YOUR_GOOGLE_USERNAME>", 
                    password="<PASSWORD_OR_APP_SPECIFIC_PASSWORD>",
                    document_key=opts.id,
                    sheet_name=opts.sheet,
                    key_column_headers=[opts.key])
    target.inject({opts.key_value:opts.fieldvalue_dict})

and use like this:

gdocs_addrow.py --id 1iZa...BqQ --key name name="Trevor B" age="31"
share|improve this answer
    
Can you explain what this does and how it helps? –  Andrew Lott Jul 31 at 14:54
    
@AndrewLott hope that's clearer. –  mbrenig Aug 1 at 16:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.