Last active
June 21, 2018 12:14
-
-
Save ViveK-PothinA/04153012dcff6b39d6ddb96d2680269c to your computer and use it in GitHub Desktop.
Find kaggle.json in Google Drive for Google Colab
This file contains 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
# Import kaggle.json from google drive | |
# This snippet will output a link which needs authentication from any google account | |
from googleapiclient.discovery import build | |
import io, os | |
from googleapiclient.http import MediaIoBaseDownload | |
from google.colab import auth | |
auth.authenticate_user() | |
drive_service = build('drive', 'v3') | |
results = drive_service.files().list( | |
q="name = 'kaggle.json'", fields="files(id)").execute() | |
kaggle_api_key = results.get('files', []) | |
# print(kaggle_api_key) | |
filename = "/content/.kaggle/kaggle.json" | |
os.makedirs(os.path.dirname(filename), exist_ok=True) | |
request = drive_service.files().get_media(fileId=kaggle_api_key[0]['id']) | |
fh = io.FileIO(filename, 'wb') | |
downloader = MediaIoBaseDownload(fh, request) | |
done = False | |
while done is False: | |
status, done = downloader.next_chunk() | |
print("Download %d%%." % int(status.progress() * 100)) | |
os.chmod(filename, 600) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment