summaryrefslogtreecommitdiff
path: root/download-images.py
blob: 7d6fa38998c4a1a6c5646338f32d81cfe0f96432 (plain)
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
#! /usr/bin/python3
import os
from shutil import copyfile
import sys

home_directory = os.path.expanduser('~')
if os.path.exists(sys.argv[1]):
    path = os.path.abspath(sys.argv[1])
else:
    print("Cannot find " + sys.argv[1])
    exit()
with open(os.path.join(home_directory, '.photocopyrc'), 'r') as f:
    lastfile = str(f.readline().rstrip())
sorter = []
for (dirname, dirs, files) in os.walk(path):
    dirn = os.path.abspath(dirname)
    for filename in files:
        if filename.endswith('.ARW'):
            if int(filename.split('DSC')[1].split(".ARW")[0]) > int(lastfile.split('DSC')[1].split(".ARW")[0]):
                sorter.append([int(filename.split('DSC')[1].split(".ARW")[0]), filename])
for f in sorted(sorter):
    dest = os.path.join(home_directory, 'photos', 'inbox')
    if not os.path.exists(dest):
        os.makedirs(dest)
    print("copying:", dirn+'/'+f[1], "--->", dest+'/'+f[1])
    copyfile(dirn+'/'+f[1], os.path.join(dest, f[1]))
    try:
        out = sorted(sorter)[-1]
        with open(os.path.join(home_directory, '.photocopyrc'), 'w') as f:
            f.write(out[1])
    except IndexError:
        pass