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'
评论列表
文章目录