[PYTHON] How to analyze with Google Colaboratory using Kaggle API

For my notes

kaggle.py


!pip install kaggle

kaggle_api.py


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', [])
filename = "/root/.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)

Recommended Posts

How to analyze with Google Colaboratory using Kaggle API
How to search Google Drive with Google Colaboratory
How to display Map using Google Map API (Android)
How to use Google Colaboratory
Try to implement linear regression using Pytorch with Google Colaboratory
How to display formulas in latex when using sympy (> = 1.4) in Google Colaboratory
Using Java's Jupyter Kernel with Google Colaboratory
How to deal with OAuth2 error when using Google APIs from Python
I want to analyze songs with Spotify API 2
How to deal with SessionNotCreatedException when using Selenium
I want to analyze songs with Spotify API 1
How to use the Google Cloud Translation API
Download files directly to Google Drive (using Google Colaboratory)
[Rails] How to calculate latitude and longitude with high accuracy using Geocoding API and display it on Google Map
Easy way to scrape with python using Google Colab
Try to make RESTful API with MVC using Flask 1.0.2
Upload to a shared drive with Google Drive API V3
How to operate Discord API with Python (bot registration)
How to use Spacy Japanese model in Google Colaboratory
Building an environment to use CaboCha with google colaboratory
Study Python with Google Colaboratory
How to update with SQLAlchemy?
How to Alter with SQLAlchemy?
How to separate strings with','
How to RDP with Fedora31
Try OpenCV with Google Colaboratory
How to Delete with SQLAlchemy?
How to extract any appointment in Google Calendar with Python
How to not load images when using PhantomJS with Selenium
How to reset password via API using Django rest framework
How to resolve CSRF Protection when using AngularJS with Django
How to hide your Google Maps API key from HTML
Try to determine food photos using Google Cloud Vision API
How to write to update Datastore to async with Google Apps Engine
How to update FC2 blog etc. using XMLRPC with python
How to deal with UnicodeDecodeError when executing google image download
Play with YouTube Data API v3 using Google API Python Client
How to easily draw the structure of a neural network on Google Colaboratory using "convnet-drawer"
How to install python using anaconda
How to cancel RT with tweepy
Analyze your site using Google Analytics-Chapter 1
Python: How to use async with
[Rails] How to display Google Map
[For non-programmers] How to walk Kaggle
[Python3] Google translate google translate without using api
How to get followers and followers from python using the Mastodon API
How to use virtualenv with PowerShell
How to deal with imbalanced data
Output cell to file with Colaboratory
I tried to analyze my favorite singer (SHISHAMO) using Spotify API
How to get started with Scrapy
How to connect to Cloud Firestore from Google Cloud Functions with python code
How to pass arguments using an instance with systemd's systemctl command
[Memo] How to use Google MµG
How to deal with DistributionNotFound errors
How to get started with Django
How to use OpenPose's Python API
How to Data Augmentation with PyTorch
How to use FTP with Python
OpenCV feature detection with Google Colaboratory
Create API using hug with mod_wsgi