From c3de28a14da0cfab52a822436e4ba5244412e366 Mon Sep 17 00:00:00 2001 From: neingeist Date: Wed, 11 Jul 2018 15:00:13 +0200 Subject: [PATCH] remember seen files --- drive-download.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drive-download.py b/drive-download.py index e1c2b8f..036a877 100644 --- a/drive-download.py +++ b/drive-download.py @@ -6,10 +6,17 @@ if sys.version_info < (3, 3): sys.exit(1) import os +import pickle import shlex from pydrive.auth import GoogleAuth from pydrive.drive import GoogleDrive +try: + with open(os.path.expanduser('~/.local/share/drive-download/seen.pickle'), 'rb') as f: + seen = pickle.load(f) +except FileNotFoundError: + seen = set() + gauth = GoogleAuth(settings_file=os.path.expanduser('~/.config/drive-download/settings.yaml')) gauth.CommandLineAuth() @@ -19,9 +26,15 @@ file_list = drive.ListFile({'q': "'{}' in parents and trashed=false".format(FOLD for file1 in file_list: if file1['mimeType'] == 'application/vnd.google-apps.folder': continue + if file1['id'] in seen: + continue + local_filename = file1['title'] print(shlex.quote(local_filename)) if not os.path.exists(local_filename): file1.GetContentFile(local_filename) + seen.add(file1['id']) + with open(os.path.expanduser('~/.local/share/drive-download/seen.pickle'), 'wb') as f: + pickle.dump(seen, f) else: raise RuntimeError("{} exists".format(shlex.quote(local_filename)))