Skip to content

Instantly share code, notes, and snippets.

@patharanordev
Last active October 12, 2020 13:57
Show Gist options
  • Save patharanordev/79576dfca708aa2e96fb391a9221beca to your computer and use it in GitHub Desktop.
Save patharanordev/79576dfca708aa2e96fb391a9221beca to your computer and use it in GitHub Desktop.
Download file from Kaggle via Kaggle own credential
from zipfile import ZipFile
from google.colab import files
!rm -rf kaggle.json
!rm -rf /root/.kaggle/kaggle.json
'''
If you found an error "TypeError: Cannot read property '_uploadFiles' of undefined",
please check cookie mode. You need to allow all cookie
'''
files.upload() #upload kaggle.json
!mkdir -p ~/.kaggle
!cp kaggle.json ~/.kaggle/
!ls ~/.kaggle
!chmod 600 /root/.kaggle/kaggle.json
!rm -rf kaggle.json
from kaggle.api.kaggle_api_extended import KaggleApi
api = KaggleApi()
api.authenticate()
targetDataDir = './data/'
# Example
zipFileName = './solar-power-generation-data.zip'
# Clear the old one
!rm -rf $targetDataDir
!rm -rf $zipFileName
# Fetch the new one
!kaggle datasets download -d anikannal/solar-power-generation-data
!mkdir -p $targetDataDir
zp = ZipFile(zipFileName)
zp.extractall(targetDataDir)
zp.close()
!rm -rf $zipFileName
for dirname, _, filenames in os.walk(targetDataDir):
for filename in filenames:
print(os.path.join(dirname, filename))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment