Created
August 12, 2018 23:21
-
-
Save omarsar/a7e28db93f6557ebba58a92a1e1d8539 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_file(file_id): | |
""" | |
Download file from Google Drive | |
Argument: file_id | |
Returns: downloaded file | |
""" | |
file_id = file_id | |
import io | |
from googleapiclient.http import MediaIoBaseDownload | |
request = drive_service.files().get_media(fileId=file_id) | |
downloaded = io.BytesIO() | |
downloader = MediaIoBaseDownload(downloaded, request) | |
done = False | |
while done is False: | |
# _ is a placeholder for a progress object that we ignore. | |
# (Our file is small, so we skip reporting progress.) | |
_, done = downloader.next_chunk() | |
downloaded.seek(0) | |
return downloaded | |
#print 'Downloaded file contents are:', downloaded.read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment