如何在 Google Drive API Python 中显示下载速度
我想修改它以显示下载速度
def download_file(id):
fileStats=file_info(id)
# showing the file stats
print("----------------------------")
print("FileName: ",fileStats['name'])
print("FileSize: ",convert_size(int(fileStats['size'])))
print("----------------------------")
request = service.files().get_media(fileId=id)
fh = io.BytesIO()
downloader = MediaIoBaseDownload(fh, request,chunksize=1048576)
done = False
while done is False:
status, done = downloader.next_chunk()
# just a function that clear the screen and displays the text passed as argument
ui_update('{1:<10}\t{2:<10}\t{0}'.format(fileStats['name'],color(convert_size(int(fileStats['size'])),Colors.orange),color(f'{round(status.progress()*100,2)}%',Colors.green)))
fh.seek(0)
with open(os.path.join(location, fileStats['name']), 'wb') as f:
f.write(fh.read())
f.close()
else:
print("File Download Cancelled!!!")