Now reads only specified files if extension is provided.
This commit is contained in:
parent
ed525ccf2f
commit
17ce459630
24
exv.py
24
exv.py
@ -32,7 +32,9 @@ TYPES = [
|
||||
"JP2"
|
||||
]
|
||||
|
||||
def extractor(input_files, start, end, recursive):
|
||||
def extractor(input_files, start, end, recursive, extensions):
|
||||
if extensions:
|
||||
extensions = [ext.upper() for ext in extensions]
|
||||
if not isinstance(input_files, type(list())):
|
||||
raise ValueError("Input files must be a list.")
|
||||
exif_dict_list = []
|
||||
@ -62,7 +64,15 @@ def extractor(input_files, start, end, recursive):
|
||||
break
|
||||
else:
|
||||
files.append(item)
|
||||
input_files = files
|
||||
if extensions:
|
||||
files_with_ext_filter = []
|
||||
for filename in files:
|
||||
if filename.split(".")[-1].upper() in extensions:
|
||||
files_with_ext_filter.append("{}".format(filename))
|
||||
input_files = files_with_ext_filter
|
||||
else:
|
||||
input_files = files
|
||||
|
||||
for input_file in input_files:
|
||||
exif_dict = {}
|
||||
if not isfile(input_file):
|
||||
@ -181,14 +191,20 @@ def extractor(input_files, start, end, recursive):
|
||||
|
||||
if __name__ == '__main__':
|
||||
import argparse
|
||||
recursive = False
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"infile", help="input file (EXV, JPG, CR2, ...). Can be more than one.", nargs='+')
|
||||
parser.add_argument("-s", "--start-date", help="start date as YYYYMMDD. If omitted, begin of the collection.", const=None)
|
||||
parser.add_argument("-e", "--end-date", help="end date as YYYYMMDD. If omitted, today", const=None)
|
||||
parser.add_argument("-R", "--recursive", help="Walk throught directory to find all files", action='store_true')
|
||||
parser.add_argument("-x", "--extension", help="Read files with this extension only (can be specified more than one time)", action='append')
|
||||
args = parser.parse_args()
|
||||
if not args.recursive:
|
||||
recursive = False
|
||||
if not args.extension:
|
||||
extensions = None
|
||||
else:
|
||||
extensions = args.extension
|
||||
if not args.start_date:
|
||||
args.start_date = "18250101" # Ok, that's the year of the 1st photography by Nicéphore Niépce. Shoul'd be enough for a start date.
|
||||
if not args.end_date:
|
||||
@ -200,4 +216,4 @@ if __name__ == '__main__':
|
||||
print("Date must be YYYYMMDD.")
|
||||
exit()
|
||||
recursive = args.recursive
|
||||
print(json.dumps(extractor(args.infile, datetime.strptime(args.start_date, "%Y%m%d"), datetime.strptime(args.end_date, "%Y%m%d"), recursive), indent=4, sort_keys=True))
|
||||
print(json.dumps(extractor(args.infile, datetime.strptime(args.start_date, "%Y%m%d"), datetime.strptime(args.end_date, "%Y%m%d"), recursive, extensions), indent=2, sort_keys=True))
|
||||
|
Loading…
Reference in New Issue
Block a user