add generic templates
This commit is contained in:
+13
-8
@@ -164,19 +164,24 @@ def parse(template, string):
|
||||
if result := re.match(reg, string):
|
||||
return result.groupdict()
|
||||
|
||||
def find_last(template, **kargs):
|
||||
#print(find_last, template, kargs)
|
||||
pattern = Path(template).as_posix()
|
||||
pattern = expandvars(pattern)
|
||||
def expand(template, **kargs):
|
||||
template = Path(template).as_posix()
|
||||
template = expandvars(template)
|
||||
|
||||
for key, value in kargs.items():
|
||||
pattern = re.sub(r'\{%s\}'%key, value, pattern)
|
||||
template = re.sub(r'\{%s\}'%key, value, template)
|
||||
|
||||
return template
|
||||
|
||||
def find_last(template, **kargs):
|
||||
|
||||
pattern = expand(template, **kargs)
|
||||
|
||||
pattern = re.sub(r'{\w+:(\d{2})d}', lambda x : '?' * int(x.groups()[0]), pattern)
|
||||
pattern = re.sub(r'{.*?}', '*', pattern)
|
||||
|
||||
print(pattern)
|
||||
|
||||
filepaths = glob.glob(pattern)
|
||||
if filepaths:
|
||||
return Path(max(filepaths))
|
||||
return Path(max(filepaths))
|
||||
else:
|
||||
print(f'No preview found for template {pattern}')
|
||||
Reference in New Issue
Block a user