-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync-client.py
More file actions
executable file
·43 lines (37 loc) · 1.32 KB
/
sync-client.py
File metadata and controls
executable file
·43 lines (37 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from pydrive.files import FileNotDownloadableError
from sys import exit
from shutil import move
SYNC_PATH="/home/kk/gdrive-sync/"
gauth = GoogleAuth()
gauth.CommandLineAuth()
drive = GoogleDrive(gauth)
# get ID of sync folder
folder_id = ""
file_list = drive.ListFile({"q": "'root' in parents and trashed=false"}).GetList()
for f in file_list:
if "sync" == f["title"]:
folder_id = f["id"]
if not folder_id:
print("Error: could not find folder 'sync' in drive")
exit(1)
sync_list = drive.ListFile({"q": f"'{folder_id}' in parents and trashed=false"}).GetList()
for f in sync_list:
try:
filename = f["title"]
print(f"Downloading {filename}")
f.GetContentFile(filename=filename, mimetype=f["mimeType"])
print(f"Download successful. Moving {filename} to {SYNC_PATH}")
try:
move(filename, SYNC_PATH)
except Exception as e:
print(f"Exception {e} on move({filename}, {SYNC_PATH})")
else:
print(f"Moving successful. Trashing {filename}")
f.Trash()
except FileNotDownloadableError as fnde:
print(f"file {f['title']} not downloadable")
except Exception as e:
print(f"Exception {e} on file {f['title']}")