qtinio

Untitled

May 8th, 2020
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. import time
  2. import httplib2
  3. from oauth2client.file import Storage
  4. from oauth2client.client import flow_from_clientsecrets
  5. from oauth2client.tools import tools
  6. import math
  7. import getopt
  8. import sys
  9. import string
  10. import datetime
  11. import gdata.spreadsheet.service
  12. import gdata.service
  13.  
  14. storage = Storage("creds.dat")
  15. credentials = storage.get()
  16. if credentials is None or credentials.invalid:
  17.     flags = tools.argparser.parse_args(args=[])
  18.     flow = flow_from_clientsecrets("client_secret.json", scope=["https://spreadsheets.google.com/feeds"])
  19.     credentials = tools.run_flow(flow, storage, flags)
  20. if credentials.access_token_expired:
  21.     credentials.refresh(httplib2.Http())
  22.  
  23. client = gdata.spreadsheet.service.SpreadsheetsService(
  24.     additional_headers={'Authorization' : 'Bearer %s' % credentials.access_token})
  25. spreadsheet_key = '1Vv-HJGcPfAjQF-VEgfO675gVEkxuWTsYnLH-Hgt8neo'
  26. entry = client.GetSpreadsheetsFeed(spreadsheet_key)
  27. print entry.title
  28.  
  29.  
  30. for i in range(25):
  31.     val = i
  32.     dict = {}
  33.     dict['date'] = time.strftime('%m/%d/%Y')
  34.     dict['time'] = time.strftime('%H:%M:%S')
  35.     dict['value'] = str(val)
  36.     print dict
  37.     entry = client.InsertRow(dict, spreadsheet_key, 'od6')
  38.     if isinstance(entry, gdata.spreadsheet.SpreadsheetsList):
  39.     print "Insert row succeeded."
  40.     else:
  41.     print "Insert row failed."
Add Comment
Please, Sign In to add comment