From 678e40334e8daf274011d9a013c7419bc9f9407b Mon Sep 17 00:00:00 2001 From: manetta Date: Wed, 29 Sep 2021 20:20:52 +0200 Subject: [PATCH] new regex, to avoid overriding Image01.png with 01.png --- command-line/update.py | 10 ++++++++-- web-interface/update.py | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/command-line/update.py b/command-line/update.py index bff69cd..8cc480f 100644 --- a/command-line/update.py +++ b/command-line/update.py @@ -81,8 +81,14 @@ def download_media(html, images, wiki): time.sleep(3) # do not overload the server # replace src link - image_path = f'/{ STATIC_FOLDER_PATH }/images/{ filename }' # here the images need to link to the / of the domain, for flask :/// confusing! this breaks the whole idea to still be able to make a local copy of the file - html = re.sub(rf'src="/book/images/.*{ filename }"', f'src="{ image_path }"', html) + image_path = f'{ STATIC_FOLDER_PATH }/images/{ filename }' # here the images need to link to the / of the domain, for flask :/// confusing! this breaks the whole idea to still be able to make a local copy of the file + matches = re.findall(rf'src="/book/images/.*?px-{ filename }"', html) # for debugging + if matches: + html = re.sub(rf'src="/book/images/.*?px-{ filename }"', f'src="{ image_path }"', html) + else: + matches = re.findall(rf'src="/book/images/.*?{ filename }"', html) # for debugging + html = re.sub(rf'src="/book/images/.*?{ filename }"', f'src="{ image_path }"', html) + # print(f'{filename}: {matches}\n------') # for debugging: each image should have the correct match! return html diff --git a/web-interface/update.py b/web-interface/update.py index f57e43f..ea7279f 100644 --- a/web-interface/update.py +++ b/web-interface/update.py @@ -82,8 +82,14 @@ def download_media(html, images, wiki): time.sleep(3) # do not overload the server # replace src link - image_path = f'/{ STATIC_FOLDER_PATH }/images/{ filename }' # here the images need to link to the / of the domain, for flask :/// confusing! this breaks the whole idea to still be able to make a local copy of the file - html = re.sub(rf'src="/book/images/.*{ filename }"', f'src="{ image_path }"', html) + image_path = f'{ STATIC_FOLDER_PATH }/images/{ filename }' # here the images need to link to the / of the domain, for flask :/// confusing! this breaks the whole idea to still be able to make a local copy of the file + matches = re.findall(rf'src="/book/images/.*?px-{ filename }"', html) # for debugging + if matches: + html = re.sub(rf'src="/book/images/.*?px-{ filename }"', f'src="{ image_path }"', html) + else: + matches = re.findall(rf'src="/book/images/.*?{ filename }"', html) # for debugging + html = re.sub(rf'src="/book/images/.*?{ filename }"', f'src="{ image_path }"', html) + # print(f'{filename}: {matches}\n------') # for debugging: each image should have the correct match! return html