drive-download/drive-download.py

23 lines
657 B
Python
Raw Normal View History

2018-07-11 12:43:29 +02:00
FOLDER = '1J_Yw3ENBfDOEjiPV2LpYIa86aAPnaVx3'
import os
2018-07-11 14:04:01 +02:00
import shlex
2018-07-11 12:43:29 +02:00
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.CommandLineAuth()
drive = GoogleDrive(gauth)
file_list = drive.ListFile({'q': "'{}' in parents and trashed=false".format(FOLDER)}).GetList()
for file1 in file_list:
if file1['mimeType'] == 'application/vnd.google-apps.folder':
continue
local_filename = file1['title']
print(local_filename)
if not os.path.exists(local_filename):
file1.GetContentFile(local_filename)
else:
2018-07-11 14:04:01 +02:00
raise RuntimeError("{} exists".format(shlex.quote(local_filename)))