Raspberry Pi and Google Sheets

Trying hard to push data onto an ordinary Google Doc, but apparently it is much more common to use sheets. Other than that, the main problem was getting the OAuth2 in place. But it works.

http://gspread.readthedocs.org/en/latest/oauth2.html

from time import sleep
from oauth2client.client import SignedJwtAssertionCredentials

import RPi.GPIO as GPIO
import gspread
import json

#Google Sheets
GDOCS_CRED = 'RPIWHEREABOUTS.json'
GDOCS_NAME = 'Test Document'

scope = ['https://spreadsheets.google.com/feeds https://docs.google.com/feeds']
json_key = json.load(open(GDOCS_CRED))
credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'].encode(), scope)

gc = gspread.authorize(credentials)
wks = gc.open(GDOCS_NAME).sheet1

wks.update_acell('B2', "EUREKA")
wks.append_row("ONE MORE")

#GPIO
led = 13
button = 11

GPIO.setmode(GPIO.BOARD)

GPIO.setup(led, GPIO.OUT)
GPIO.setup(button, GPIO.IN)

GPIO.output(led, False)

#Main Loop
while(1):
	if(GPIO.input(button)):
		GPIO.output(led, False)
	else:
		GPIO.output(led, True)
	sleep(1)