Created
May 27, 2019 00:37
-
-
Save RodrigoCMoraes/e179a67f1c36be57c82ca54cc1bfcd4b to your computer and use it in GitHub Desktop.
Getting file from Google Drive by PyDrive
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
#@title Dataset info { form-width: "800px" } | |
# e.g GOOGLE_DRIVE_FILE_URL: https://drive.google.com/open?id=1CZyDkHHjS8SUVBF7fBwoTAF6xSpLmD4P7 | |
LinkFile = "GOOGLE_DRIVE_FILE_URL" #@param {type:"string"} | |
# e.g GOOGLE_DRIVE_FILENAME_WITH_EXTENSION: Local History.csv | |
Filename = "GOOGLE_DRIVE_FILENAME_WITH_EXTENSION" #@param {type:"string"} | |
Filename = Filename.replace(' ', '\ ') | |
# Install the PyDrive wrapper & import libraries. | |
# This only needs to be done once per notebook. | |
!pip install -U -q PyDrive | |
from pydrive.auth import GoogleAuth | |
from pydrive.drive import GoogleDrive | |
from google.colab import auth | |
from oauth2client.client import GoogleCredentials | |
# Authenticate and create the PyDrive client. | |
# This only needs to be done once per notebook. | |
auth.authenticate_user() | |
gauth = GoogleAuth() | |
gauth.credentials = GoogleCredentials.get_application_default() | |
drive = GoogleDrive(gauth) | |
# Download a file based on its file ID. | |
# | |
# A file ID looks like: laggVyWshwcyP6kEI-y_W3P8D26sz | |
file_id = LinkFile.split('=')[-1] | |
downloaded = drive.CreateFile({'id': file_id}) | |
downloaded.GetContentFile(Filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment