-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgoogle_drive.py
More file actions
27 lines (21 loc) · 1.12 KB
/
google_drive.py
File metadata and controls
27 lines (21 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import io
from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient.http import MediaIoBaseDownload
from googleapiclient.discovery import build
class Drive:
def __init__(self, google_secrets):
self.secrets = google_secrets
self.scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
self.creds = ServiceAccountCredentials.from_json_keyfile_dict(self.secrets["tokens"]["serviceaccount"],
self.scope)
self.drive_service = build('drive', 'v3', credentials=self.creds)
def download_file(self, file_id, filename):
# Get file from Google Drive
request = self.drive_service.files().get_media(fileId=file_id)
fh = io.FileIO(filename, mode='wb')
downloader = MediaIoBaseDownload(fh, request)
done = False
# print("Download: {}% complete".format(int(0 * 100.0)))
while done is False:
status, done = downloader.next_chunk()
# print("Download: {}% complete".format(int(status.progress() * 100.0)))