Now reads only specified files if extension is provided.
This commit is contained in:
parent
bb90e192e9
commit
47b87835f9
24
exv.py
24
exv.py
@ -32,7 +32,9 @@ TYPES = [
|
|||||||
"JP2"
|
"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())):
|
if not isinstance(input_files, type(list())):
|
||||||
raise ValueError("Input files must be a list.")
|
raise ValueError("Input files must be a list.")
|
||||||
exif_dict_list = []
|
exif_dict_list = []
|
||||||
@ -62,7 +64,15 @@ def extractor(input_files, start, end, recursive):
|
|||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
files.append(item)
|
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:
|
for input_file in input_files:
|
||||||
exif_dict = {}
|
exif_dict = {}
|
||||||
if not isfile(input_file):
|
if not isfile(input_file):
|
||||||
@ -181,14 +191,20 @@ def extractor(input_files, start, end, recursive):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import argparse
|
import argparse
|
||||||
recursive = False
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"infile", help="input file (EXV, JPG, CR2, ...). Can be more than one.", nargs='+')
|
"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("-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("-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("-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()
|
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:
|
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.
|
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:
|
if not args.end_date:
|
||||||
@ -200,4 +216,4 @@ if __name__ == '__main__':
|
|||||||
print("Date must be YYYYMMDD.")
|
print("Date must be YYYYMMDD.")
|
||||||
exit()
|
exit()
|
||||||
recursive = args.recursive
|
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…
x
Reference in New Issue
Block a user