Fix ordigi utils

This commit is contained in:
Cédric Leporcq 2021-11-11 18:54:41 +01:00
parent 26845cf56b
commit 506869ca4f
1 changed files with 6 additions and 7 deletions

View File

@ -38,8 +38,8 @@ def distance_between_two_points(lat1, lon1, lat2, lon2):
def get_date_regex(string, user_regex=None): def get_date_regex(string, user_regex=None):
if user_regex is not None: if user_regex:
matches = re.findall(user_regex, string) regex = {'a': re.compile(user_regex)}
else: else:
regex = { regex = {
# regex to match date format type %Y%m%d, %y%m%d, %d%m%Y, # regex to match date format type %Y%m%d, %y%m%d, %d%m%Y,
@ -59,8 +59,7 @@ def get_date_regex(string, user_regex=None):
), ),
} }
for i, rx in regex.items(): return regex
yield i, rx
def get_date_from_string(string, user_regex=None): def get_date_from_string(string, user_regex=None):
@ -69,7 +68,7 @@ def get_date_from_string(string, user_regex=None):
# 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): for i, rx in get_date_regex(string, user_regex).items():
match = re.findall(rx, string) match = re.findall(rx, string)
if match != []: if match != []:
if i == 'c': if i == 'c':
@ -110,7 +109,7 @@ def split_part(dedup_regex, path_part, items=None):
if not items: if not items:
items = [] items = []
regex = dedup_regex.pop(0) regex = dedup_regex.pop()
parts = re.split(regex, path_part) parts = re.split(regex, path_part)
# Loop thought part, search matched regex part and proceed with # Loop thought part, search matched regex part and proceed with
# next regex for others parts # next regex for others parts
@ -123,7 +122,7 @@ def split_part(dedup_regex, path_part, items=None):
items.append(part[1:]) items.append(part[1:])
else: else:
items.append(part) items.append(part)
elif dedup_regex != []: elif dedup_regex:
# Others parts # Others parts
items = split_part(dedup_regex, part, items) items = split_part(dedup_regex, part, items)
else: else: