Code to download files from google drive to colab
2018-03-26 15:06
447 查看
Code:
def download_from_google_drive(file_name_prefix): # 1. Authenticate and create the PyDrive client. auth.authenticate_user() gauth = GoogleAuth() gauth.credentials = GoogleCredentials.get_application_default() drive = GoogleDrive(gauth) # choose a local (colab) directory to store the data. local_download_path = os.path.expanduser('~/data') try: os.makedirs(local_download_path) except: pass # 2. Auto-iterate using the query syntax # https://developers.google.com/drive/v2/web/search-parameters file_list = drive.ListFile( {'q': "title contains '%s'" % (file_name_prefix) }).GetList() files_dict = {} for f in file_list: # 3. Create & download by id. print('title: %s, id: %s' % (f['title'], f['id'])) fname = os.path.join(local_download_path, f['title']) if not os.path.exists(fname): print('downloading to {}'.format(fname)) f_ = drive.CreateFile({'id': f['id']}) f_.GetContentFile(fname) print('Download Completed!') files_dict[ f['title'] ] = fname # with open(fname, 'r') as f: # print(f.read()) return files_dict, local_download_path
References:
Search for Files and Team DrivesFiles: list
相关文章推荐
- How to Download APK Files from Google Play Store
- How to download codes from Google Code
- use python to download files from http servers
- How to download files from the Linux command line
- copy files from usb drive to vsphere 5
- Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/adp;
- Drive More Search Traffic to Your Maps API Site by Including KML Files in a Sitemap——Google 地图 API 文档之五
- How to enable download EXE files from the Sharepoint website
- Copy code from eclipse to word, save syntax.
- How to extract msu/msp/msi/exe files from the command line
- iPhone开发:如何阻止文件被iTunes和iCloud同步 How do I prevent files from being backed up to iCloud and iTunes?
- Beginning Google Maps Applications with Rails and Ajax: From Novice to Professional
- RSOD8-8% off code to buy old school gold from RSorder Until Dec. 2 for Quality of Life & Bugfixes
- how to generate pb file from ckpt files?
- How to delete ASO files from Flash
- ubuntu更新时出现错误 E: Some index files failed to download, they have been ignored, or old ones used inst
- How to copy files remotely from another machine
- How To Install Ubuntu 12.04 from USB Drive
- How to move ASM database files from one diskgroup to another
- DOWNLOAD FROM ITAB TO EXCEL