-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexif-date-2-filename.py
61 lines (49 loc) · 2.06 KB
/
exif-date-2-filename.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
import shutil
import exifread
def convert_timestamp(ExifTime):
# converts Exif Timestamp '2015:12:27 09:43:44'
# To ISO like Timestamp '2015-12-27T09.43.44'
# attrs = dir(ExifTime)
values = getattr(ExifTime, 'values')
# values = '2015:12:27 09:43:44'
date = values[:10].replace(':', '-')
time = values[11:].replace(':', '.')
timestamp = date + 'T' + time
return timestamp
# def rename_pictures(source='testfiles/source',
# destination='testfiles/destination'):
def rename_pictures(source='testfiles/source'):
destination=source
for file in os.listdir(source):
if file != '.DS_Store':
filename = os.path.splitext(file)[0]
extension = os.path.splitext(file)[1]
f = open(source+'/'+file, 'rb')
tags = exifread.process_file(f)
if 'EXIF DateTimeOriginal' in tags.keys():
ExifTime = tags['EXIF DateTimeOriginal']
timestamp = convert_timestamp(ExifTime)
shutil.copy(source + '/'
+ file, destination
+ '/' + timestamp
+ '--' + filename
+ '__'
+ extension)
else:
print('no EXIF Data found for %s' % file)
shutil.copy(source + '/'
+ file, destination
+ '/' + filename
+ '__' + 'noexif'
+ extension)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description='Create a ArcHydro schema')
parser.add_argument('--source', metavar='path', required=True,
help='path to source folder')
# parser.add_argument('--destination', metavar='path', required=True,
# help='path to destination folder')
args = parser.parse_args()
# rename_pictures(source=args.source, destination=args.destination)
rename_pictures(source=args.source)