extract functions to read/save seen
This commit is contained in:
parent
1c55509b0c
commit
8a2203ade7
1 changed files with 18 additions and 10 deletions
|
@ -15,16 +15,19 @@ from pydrive.auth import GoogleAuth
|
||||||
from pydrive.drive import GoogleDrive
|
from pydrive.drive import GoogleDrive
|
||||||
|
|
||||||
|
|
||||||
try:
|
def read_seen():
|
||||||
with open(os.path.expanduser('~/.local/share/drive-download/seen.pickle'), 'rb') as f:
|
global seen
|
||||||
seen = pickle.load(f)
|
try:
|
||||||
except FileNotFoundError:
|
with open(os.path.expanduser('~/.local/share/drive-download/seen.pickle'), 'rb') as f:
|
||||||
seen = set()
|
seen = pickle.load(f)
|
||||||
|
except FileNotFoundError:
|
||||||
|
seen = set()
|
||||||
|
|
||||||
gauth = GoogleAuth(settings_file=os.path.expanduser('~/.config/drive-download/settings.yaml'))
|
|
||||||
gauth.CommandLineAuth()
|
|
||||||
|
|
||||||
drive = GoogleDrive(gauth)
|
def save_seen():
|
||||||
|
global seen
|
||||||
|
with open(os.path.expanduser('~/.local/share/drive-download/seen.pickle'), 'wb') as f:
|
||||||
|
pickle.dump(seen, f)
|
||||||
|
|
||||||
|
|
||||||
def folder_id(folder_name):
|
def folder_id(folder_name):
|
||||||
|
@ -34,6 +37,12 @@ def folder_id(folder_name):
|
||||||
return file1['id']
|
return file1['id']
|
||||||
|
|
||||||
|
|
||||||
|
read_seen()
|
||||||
|
|
||||||
|
gauth = GoogleAuth(settings_file=os.path.expanduser('~/.config/drive-download/settings.yaml'))
|
||||||
|
gauth.CommandLineAuth()
|
||||||
|
drive = GoogleDrive(gauth)
|
||||||
|
|
||||||
file_query = "'%s' in parents and trashed=false" % folder_id(FOLDER)
|
file_query = "'%s' in parents and trashed=false" % folder_id(FOLDER)
|
||||||
file_list = drive.ListFile({'q': file_query}).GetList()
|
file_list = drive.ListFile({'q': file_query}).GetList()
|
||||||
|
|
||||||
|
@ -56,8 +65,7 @@ for file1 in file_list:
|
||||||
if not os.path.exists(local_filename):
|
if not os.path.exists(local_filename):
|
||||||
file1.GetContentFile(local_filename)
|
file1.GetContentFile(local_filename)
|
||||||
seen.add(file1['id'])
|
seen.add(file1['id'])
|
||||||
with open(os.path.expanduser('~/.local/share/drive-download/seen.pickle'), 'wb') as f:
|
save_seen()
|
||||||
pickle.dump(seen, f)
|
|
||||||
else:
|
else:
|
||||||
print("{} exists locally!".format(shlex.quote(local_filename)))
|
print("{} exists locally!".format(shlex.quote(local_filename)))
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue