diff options
Diffstat (limited to 'download-photos-gopro.py')
-rwxr-xr-x | download-photos-gopro.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/download-photos-gopro.py b/download-photos-gopro.py new file mode 100755 index 0000000..6bbce6e --- /dev/null +++ b/download-photos-gopro.py @@ -0,0 +1,33 @@ +#! /usr/bin/python3 +import os +from shutil import copyfile +import sys +from pathlib import Path +if os.path.exists(sys.argv[1]): + path = os.path.abspath(sys.argv[1]) +else: + print("Cannot find " + sys.argv[1]) + exit() +with open('/home/lxf/.goprophotorc', 'r') as f: + lastfile = str(f.readline().rstrip()) +sorter = [] +LAST = None +for (dirname, dirs, files) in os.walk(path): + dirn = os.path.abspath(dirname) + for filename in files: + if Path(filename).suffix == '.GPR' or Path(filename).suffix == '.JPG': + photo = filename.split('.')[0][5:] + if int(photo) > int(lastfile.split('.')[0][5:]): + sorter.append([int(filename.split('.')[0][5:]), filename]) +for f in sorted(sorter): + dest = '/home/lxf/pictures/inbox/' + if not os.path.exists(dest): + os.makedirs(dest) + print("copying:", dirn+'/'+f[1], "--->", dest+f[1]) + copyfile(dirn+'/'+f[1], dest+f[1]) + try: + out = sorted(sorter)[-1] + with open('/home/lxf/.goprophotorc', 'w') as f: + f.write(out[1]) + except IndexError: + pass |