drive-download/drive-download.py

41 lines
1.2 KiB
Python
Raw Normal View History

2018-07-11 12:43:29 +02:00
FOLDER = '1J_Yw3ENBfDOEjiPV2LpYIa86aAPnaVx3'
2018-07-11 14:06:30 +02:00
import sys
if sys.version_info < (3, 3):
sys.stderr.write("Sorry, requires at least Python 3.3\n")
sys.exit(1)
2018-07-11 12:43:29 +02:00
import os
2018-07-11 15:00:13 +02:00
import pickle
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
2018-07-11 15:00:13 +02:00
try:
with open(os.path.expanduser('~/.local/share/drive-download/seen.pickle'), 'rb') as f:
seen = pickle.load(f)
except FileNotFoundError:
seen = set()
2018-07-11 14:13:22 +02:00
gauth = GoogleAuth(settings_file=os.path.expanduser('~/.config/drive-download/settings.yaml'))
2018-07-11 12:43:29 +02:00
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
2018-07-11 15:00:13 +02:00
if file1['id'] in seen:
continue
2018-07-11 12:43:29 +02:00
local_filename = file1['title']
2018-07-11 14:13:42 +02:00
print(shlex.quote(local_filename))
2018-07-11 12:43:29 +02:00
if not os.path.exists(local_filename):
file1.GetContentFile(local_filename)
2018-07-11 15:00:13 +02:00
seen.add(file1['id'])
with open(os.path.expanduser('~/.local/share/drive-download/seen.pickle'), 'wb') as f:
pickle.dump(seen, f)
2018-07-11 12:43:29 +02:00
else:
2018-07-11 14:04:01 +02:00
raise RuntimeError("{} exists".format(shlex.quote(local_filename)))