Code:
def download_from_google_drive(file_name_prefix):
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
local_download_path = os.path.expanduser('~/data')
try:
os.makedirs(local_download_path)
except: pass
file_list = drive.ListFile(
{'q': "title contains '%s'" % (file_name_prefix) }).GetList()
files_dict = {}
for f in file_list:
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
return files_dict, local_download_path
References:
Search for Files and Team Drives
Files: list