-
Notifications
You must be signed in to change notification settings - Fork 0
/
move_pictures.py
executable file
·42 lines (29 loc) · 1.19 KB
/
move_pictures.py
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
#! /usr/bin/env python
import exifread # pip install ExifRead
import datetime
import glob
import os
import argparse
parser = argparse.ArgumentParser(description='Move images')
parser.add_argument('--dryrun', action="store_true", default=False)
parser.add_argument('--inputpath', dest="inputpath", default=os.getcwd())
parser.add_argument('--outputpath', dest="outputpath", default=os.getcwd())
options = parser.parse_args()
print options
for filename in glob.glob(os.path.join(options.inputpath, "DSC_*.JPG")):
tags = exifread.process_file(open(filename, 'rb'))
picture_time = datetime.datetime.strptime(
str(tags['Image DateTime']),
'%Y:%m:%d %H:%M:%S')
# move all pictures taken before 5 o'clock into the previous day
picture_time = picture_time - datetime.timedelta(hours=5)
directory_name = os.path.join(
options.outputpath,
"Nikon",
picture_time.strftime("%Y-%m-%d__"))
new_path = os.path.join(directory_name, os.path.basename(filename))
if not os.path.exists(directory_name) and not options.dryrun:
os.makedirs(directory_name)
if not options.dryrun:
os.rename(filename, new_path)
print filename, "->", new_path