Spaces:
Runtime error
Runtime error
| from googleapiclient.discovery import build | |
| from google.oauth2 import service_account | |
| from googleapiclient.http import MediaFileUpload | |
| import pdb | |
| import gradio as gr | |
| ''' | |
| Usage: python loacl/checkdata.py <google_file_id> | |
| ''' | |
| # 来自Google Cloud控制台的JSON凭据文件 | |
| credentials_file = "./src/peerless-window-254907-b386b71c0d99.json" | |
| api_version = 'v3' | |
| # 创建服务对象 | |
| credentials = service_account.Credentials.from_service_account_file( | |
| credentials_file, scopes=['https://www.googleapis.com/auth/drive']) | |
| service = build('drive', api_version, credentials=credentials) | |
| # 列出文件 | |
| results = service.files().list().execute() | |
| files = results.get('files', []) | |
| print(files) | |
| from googleapiclient.http import MediaIoBaseDownload | |
| import io | |
| import sys | |
| file_id = sys.argv[1] | |
| if file_id == "all": | |
| results = service.files().list().execute() | |
| files = results.get('files', []) | |
| # download all files | |
| for file in files: | |
| request = service.files().get_media(fileId=file['id']) | |
| with open("download/" + file['name'], 'wb') as file_obj: | |
| downloader = MediaIoBaseDownload(file_obj, request) | |
| done = False | |
| while not done: | |
| status, done = downloader.next_chunk() | |
| print(f"Download {int(status.progress() * 100)}%.") | |
| # "1YjON2ObGM826KaaqF-sKM7CO0tAtzWGg" | |
| # Get the file's metadata | |
| else: | |
| file = service.files().get(fileId=file_id).execute() | |
| request = service.files().get_media(fileId=file_id) | |
| with open(file['name'], 'wb') as file_obj: | |
| downloader = MediaIoBaseDownload(file_obj, request) | |
| done = False | |
| while not done: | |
| status, done = downloader.next_chunk() | |
| print(f"Download {int(status.progress() * 100)}%.") | |
| print(f"Downloaded: {file['name']}") | |
| pdb.set_trace() |