Remove confusing unused argument from get_date_regex
This commit is contained in:
parent
a9913e61d9
commit
11291a582e
|
@ -135,7 +135,7 @@ class FPath:
|
||||||
elif item == 'name':
|
elif item == 'name':
|
||||||
# Remove date prefix added to the name.
|
# Remove date prefix added to the name.
|
||||||
part = stem
|
part = stem
|
||||||
for regex in utils.get_date_regex(stem).values():
|
for regex in utils.get_date_regex().values():
|
||||||
part = re.sub(regex, '', part)
|
part = re.sub(regex, '', part)
|
||||||
elif item == 'date':
|
elif item == 'date':
|
||||||
date = metadata['date_media']
|
date = metadata['date_media']
|
||||||
|
|
|
@ -37,7 +37,8 @@ def distance_between_two_points(lat1, lon1, lat2, lon2):
|
||||||
return r * sqrt(x * x + y * y)
|
return r * sqrt(x * x + y * y)
|
||||||
|
|
||||||
|
|
||||||
def get_date_regex(string, user_regex=None):
|
def get_date_regex(user_regex=None):
|
||||||
|
"""Return date regex generator"""
|
||||||
if user_regex:
|
if user_regex:
|
||||||
regex = {'a': re.compile(user_regex)}
|
regex = {'a': re.compile(user_regex)}
|
||||||
else:
|
else:
|
||||||
|
@ -63,13 +64,14 @@ def get_date_regex(string, user_regex=None):
|
||||||
|
|
||||||
|
|
||||||
def get_date_from_string(string, user_regex=None):
|
def get_date_from_string(string, user_regex=None):
|
||||||
|
"""Retrieve date stamp from string"""
|
||||||
# If missing datetime from EXIF data check if filename is in datetime format.
|
# If missing datetime from EXIF data check if filename is in datetime format.
|
||||||
# For this use a user provided regex if possible.
|
# For this use a user provided regex if possible.
|
||||||
# Otherwise assume a filename such as IMG_20160915_123456.jpg as default.
|
# Otherwise assume a filename such as IMG_20160915_123456.jpg as default.
|
||||||
|
|
||||||
matches = []
|
matches = []
|
||||||
for i, rx in get_date_regex(string, user_regex).items():
|
for i, regex in get_date_regex(user_regex).items():
|
||||||
match = re.findall(rx, string)
|
match = re.findall(regex, string)
|
||||||
if match != []:
|
if match != []:
|
||||||
if i == 'c':
|
if i == 'c':
|
||||||
match = [('20' + match[0][0], match[0][1], match[0][2])]
|
match = [('20' + match[0][0], match[0][1], match[0][2])]
|
||||||
|
@ -80,7 +82,7 @@ def get_date_from_string(string, user_regex=None):
|
||||||
if len(match) != 1:
|
if len(match) != 1:
|
||||||
# The time string is not uniq
|
# The time string is not uniq
|
||||||
continue
|
continue
|
||||||
matches.append((match[0], rx))
|
matches.append((match[0], regex))
|
||||||
# We want only the first match for the moment
|
# We want only the first match for the moment
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -89,11 +91,6 @@ def get_date_from_string(string, user_regex=None):
|
||||||
try:
|
try:
|
||||||
# Convert str to int
|
# Convert str to int
|
||||||
date_object = tuple(map(int, matches[0][0]))
|
date_object = tuple(map(int, matches[0][0]))
|
||||||
|
|
||||||
time = False
|
|
||||||
if len(date_object) > 3:
|
|
||||||
time = True
|
|
||||||
|
|
||||||
date = datetime(*date_object)
|
date = datetime(*date_object)
|
||||||
except (KeyError, ValueError):
|
except (KeyError, ValueError):
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -86,7 +86,7 @@ class TestFPath:
|
||||||
assert part == file_path.suffix[1:], file_path
|
assert part == file_path.suffix[1:], file_path
|
||||||
elif item == 'name':
|
elif item == 'name':
|
||||||
expected_part = file_path.stem
|
expected_part = file_path.stem
|
||||||
for rx in utils.get_date_regex(expected_part).values():
|
for rx in utils.get_date_regex().values():
|
||||||
part = re.sub(rx, '', expected_part)
|
part = re.sub(rx, '', expected_part)
|
||||||
assert part == expected_part, file_path
|
assert part == expected_part, file_path
|
||||||
elif item == 'custom':
|
elif item == 'custom':
|
||||||
|
|
Loading…
Reference in New Issue