drive.py 文件源码

python
阅读 43 收藏 0 点赞 0 评论 0

项目:GoogleBot 作者: MarcoBuster 项目源码 文件源码
def download(user, file, msg):
    def startdownload(_request):
        downloader = MediaIoBaseDownload(fh, _request)
        done = False
        while not done:
            status, done = downloader.next_chunk()
            try:
                msg.edit(user.getstr('drive_downloading_progress')
                         .format(p=int(status.progress() * 100)))
            except botogram.api.APIError:
                pass

    os.chdir('/tmp')  # Sorry Windows users
    fh = io.FileIO(file.get('name'), 'wb')

    service = login(user)
    try:
        request = service.files().get_media(fileId=file.get('id'))
        startdownload(request)
        return '/tmp/' + file.get('name')
    except:
        request = service.files().export_media(fileId=file.get('id'), mimeType='application/pdf')
        startdownload(request)
        os.rename('/tmp/' + file.get('name'), '/tmp/' + file.get('name') + '.pdf')
        return '/tmp/' + file.get('name') + '.pdf'
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号