當前位置: 首頁>>代碼示例>>Python>>正文


Python drive.GoogleDrive方法代碼示例

本文整理匯總了Python中pydrive.drive.GoogleDrive方法的典型用法代碼示例。如果您正苦於以下問題:Python drive.GoogleDrive方法的具體用法?Python drive.GoogleDrive怎麽用?Python drive.GoogleDrive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pydrive.drive的用法示例。


在下文中一共展示了drive.GoogleDrive方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: getDrive

# 需要導入模塊: from pydrive import drive [as 別名]
# 或者: from pydrive.drive import GoogleDrive [as 別名]
def getDrive(drive=None, gauth=None):
    if not drive:
        if not gauth:
            gauth = GoogleAuth(settings_file=SETTINGS_YAML)
        # Try to load saved client credentials
        gauth.LoadCredentialsFile(CREDENTIALS)
        if gauth.access_token_expired:
            # Refresh them if expired
            try:
                gauth.Refresh()
            except RefreshError as e:
                log.error("Google Drive error: %s", e)
            except Exception as e:
                log.exception(e)
        else:
            # Initialize the saved creds
            gauth.Authorize()
        # Save the current credentials to a file
        return GoogleDrive(gauth)
    if drive.auth.access_token_expired:
        try:
            drive.auth.Refresh()
        except RefreshError as e:
            log.error("Google Drive error: %s", e)
    return drive 
開發者ID:janeczku,項目名稱:calibre-web,代碼行數:27,代碼來源:gdriveutils.py

示例2: __init__

# 需要導入模塊: from pydrive import drive [as 別名]
# 或者: from pydrive.drive import GoogleDrive [as 別名]
def __init__(self, *args, **kwargs):
        super(GDriveWriter, self).__init__(*args, **kwargs)
        from pydrive.auth import GoogleAuth
        from pydrive.drive import GoogleDrive
        gauth = GoogleAuth()
        files_tmp_path = tempfile.mkdtemp()
        client_secret_file = os.path.join(files_tmp_path, 'secret.json')
        with open(client_secret_file, 'w') as f:
            f.write(json.dumps(self.read_option('client_secret')))
        gauth.LoadClientConfigFile(client_secret_file)
        credentials_file = os.path.join(files_tmp_path, 'credentials.json')
        with open(credentials_file, 'w') as f:
            f.write(json.dumps(self.read_option('credentials')))
        gauth.LoadCredentialsFile(credentials_file)
        shutil.rmtree(files_tmp_path)
        self.drive = GoogleDrive(gauth)
        self.set_metadata('files_counter', Counter())
        self.set_metadata('files_written', []) 
開發者ID:scrapinghub,項目名稱:exporters,代碼行數:20,代碼來源:gdrive_writer.py

示例3: cleanup

# 需要導入模塊: from pydrive import drive [as 別名]
# 或者: from pydrive.drive import GoogleDrive [as 別名]
def cleanup(config):
        gauth = GoogleDriveActionBase.GoogleDriveActionBase.authenticate(config)
        drive = GoogleDrive(gauth)
        retain_from_date = datetime.today() - timedelta(days=int(config.config_obj.get('GoogleDriveUploadAction', 'file_retention_days')))
        file_list_len = 1
        logger.debug(drive.GetAbout())
        while file_list_len > 0:
            file_list = drive.ListFile({'q': "properties has { key='source' and value='MotionNotify' and visibility='PRIVATE'} and modifiedDate<'"
                    + retain_from_date.strftime("%Y-%m-%d") + "'"}).GetList()

            file_list_len = file_list.__len__()
            logger.info("GoogleDriveCleanAction - removing " + file_list_len.__str__() + " files")

            print(file_list.__len__())
            for file1 in file_list:
                logger.debug('GoogleDriveUploadAction Removing: title: %s, id: %s, createdDate: %s, parents: %s' % (file1['title'], file1['id'], file1['createdDate'], file1['parents']))
                file1.Delete() 
開發者ID:amdean,項目名稱:motion-notify,代碼行數:19,代碼來源:GoogleDriveCleanupAction.py

示例4: driveAuthorization

# 需要導入模塊: from pydrive import drive [as 別名]
# 或者: from pydrive.drive import GoogleDrive [as 別名]
def driveAuthorization():
    """Authorizes access to the Google Drive"""
    
    gauth = GoogleAuth()
    gauth.LocalWebserverAuth() # Creates local webserver and auto handles authentication.
    drive = GoogleDrive(gauth)
    return drive 
開發者ID:ugroot,項目名稱:GROOT,代碼行數:9,代碼來源:authenticator.py

示例5: get_from_drive

# 需要導入模塊: from pydrive import drive [as 別名]
# 或者: from pydrive.drive import GoogleDrive [as 別名]
def get_from_drive(idv):
  gauth = GoogleAuth()
  gauth.credentials = GoogleCredentials.get_application_default()
  drive = GoogleDrive(gauth)
  last_weight_file = drive.CreateFile({'id': idv}) 
  last_weight_file.GetContentFile('DenseNet-40-12-CIFAR10.h5') 
開發者ID:ambujraj,項目名稱:hacktoberfest2018,代碼行數:8,代碼來源:DenseNet_CIFAR10.py

示例6: authorize_google_drive

# 需要導入模塊: from pydrive import drive [as 別名]
# 或者: from pydrive.drive import GoogleDrive [as 別名]
def authorize_google_drive():
    global GAUTH
    global DRIVE
    if GAUTH is None or DRIVE is None:
        GAUTH = GoogleAuth()
        # Creates local webserver and auto handles authentication.
        GAUTH.LoadClientConfigFile(client_config_file=GRDIVE_CONFIG_PATH)
        GAUTH.LocalWebserverAuth()
        DRIVE = GoogleDrive(GAUTH)
        return True
    else:
        return True 
開發者ID:marl,項目名稱:medleydb,代碼行數:14,代碼來源:download.py

示例7: setup_drive

# 需要導入模塊: from pydrive import drive [as 別名]
# 或者: from pydrive.drive import GoogleDrive [as 別名]
def setup_drive(config):
        gauth = GoogleDriveActionBase.GoogleDriveActionBase.authenticate(config)
        return GoogleDrive(gauth) 
開發者ID:amdean,項目名稱:motion-notify,代碼行數:5,代碼來源:GoogleDriveUploadAction.py

示例8: upload

# 需要導入模塊: from pydrive import drive [as 別名]
# 或者: from pydrive.drive import GoogleDrive [as 別名]
def upload(file_path, description=None):
    try:
        gauth = GoogleAuth()
        # gauth.LocalWebserverAuth()

        # Try to load saved client credentials
        credential_file = os.getenv('GOOGLE_DRIVE_CREDENTIAL_FILE')
        gauth.LoadCredentialsFile(credential_file)
        if gauth.credentials is None:
            # Authenticate if they're not there
            gauth.LocalWebserverAuth()
        elif gauth.access_token_expired:
            # Refresh them if expired
            gauth.Refresh()
        else:
            # Initialize the saved creds
            gauth.Authorize()
        # end if

        # Save the current credentials to a file
        gauth.SaveCredentialsFile(credential_file)

        drive = GoogleDrive(gauth)
        folder_id = os.getenv('GOOGLE_DRIVE_FOLDER_ID')
        filename_w_ext = os.path.basename(file_path)
        filename, file_extension = os.path.splitext(filename_w_ext)

        # Upload file to folder
        f = drive.CreateFile(
            {"parents": [{"kind": "drive#fileLink", "id": folder_id}]})
        f['title'] = filename_w_ext

        # Make sure to add the path to the file to upload below.
        f.SetContentFile(file_path)
        f.Upload()

        logger.info(f['id'])
        return f['id']
    except Exception:
        logger.exception('Failed to upload %s', file_path)
    # end try
    return None
# end def 
開發者ID:dipu-bd,項目名稱:lightnovel-crawler,代碼行數:45,代碼來源:uploader.py


注:本文中的pydrive.drive.GoogleDrive方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。