예제 #1
0
def uploadTaskfile(path):
    # If the credentials don't exist or are invalid run through the native client
    # flow. The Storage object will ensure that if successful the good
    # credentials will get written back to the file.
    storage = file.Storage('credentials_googledrive.dat')
    credentials = storage.get()
    if credentials is None or credentials.invalid:
        wx.MessageBox("Click OK to open webbrowser and authorize TaskCoach to connect to Google Drive",'Backup failed',wx.OK|wx.ICON_INFORMATION)
        credentials = tools.run_flow(FLOW, storage,parser.parse_args(""))
        if credentials is None:
            return False

    FILENAME = path
    TITLE = os.path.basename(path)
    DESCRIPTION = "A file saved in Taskcoach"

    # Create an httplib2.Http object and authorize it with our credentials
    http = httplib2.Http()
    http = credentials.authorize(http)

    drive_service = discovery.build('drive', 'v2', http=http)

    # Insert a file
    media_body = discovery.MediaFileUpload(FILENAME, mimetype='text/plain', resumable=True)
    body = {
        'title': TITLE,
        'description': DESCRIPTION,
        'mimeType': 'text/plain'
    }

    file1 = drive_service.files().insert(body=body, media_body=media_body).execute()

    return True
예제 #2
0
def connect(argv):
  # Parse the command-line flags.
  flags = parser.parse_args(argv[1:])

  # If the credentials don't exist or are invalid run through the native client
  # flow. The Storage object will ensure that if successful the good
  # credentials will get written back to the file.
  storage = file.Storage('credentials.dat')
  credentials = storage.get()
  if credentials is None or credentials.invalid:
    wx.MessageBox("Click OK to open webbrowser and authorize TaskCoach to access your Google Tasks",'Authorization',wx.OK|wx.ICON_INFORMATION)
    credentials = tools.run_flow(FLOW, storage, flags)
    if credentials is None:
        return None
  # Create an httplib2.Http object to handle our HTTP requests and authorize it
  # with our good Credentials.
  http = httplib2.Http()
  http = credentials.authorize(http)

  # Construct the service object for the interacting with the Tasks API.
  return discovery.build('tasks', 'v1', http=http)