import sys import re with open('tmp_home_current.html', 'r', encoding='utf-8') as f: html = f.read() # 1. Find and extract the image block img_regex = r'(\s*
{"align":"center"} -->\s*
\s*\s*
\s*)' m = re.search(img_regex, html, re.DOTALL) if not m: print("Error: Could not find image block string.") sys.exit(1) img_block_str = m.group(1) # Remove the original image block html = html.replace(img_block_str + '\n\n', '') html = html.replace(img_block_str + '\n', '') html = html.replace(img_block_str, '') # Modify the image block new_img_block_str = img_block_str.replace('', '') new_img_block_str = new_img_block_str.replace('
', '
') new_img_block_str = new_img_block_str.replace('max-width:100%', 'width:275px;max-width:100%') # Add the modified image block at the very top of the html html = new_img_block_str + '\n\n' + html # 2. Modify "What they're Saying" block padding old_saying_regex = r'(\s*
\s*

What they\'re Saying

)' m2 = re.search(old_saying_regex, html, re.DOTALL) if not m2: print("Error: Could not find exact saying block string.") sys.exit(1) # Replace the "bottom":"60px" and padding-bottom:60px with 0px new_saying = m2.group(0).replace('"bottom":"60px"', '"bottom":"0px"').replace('padding-bottom:60px', 'padding-bottom:0px') html = html.replace(m2.group(0), new_saying) with open('tmp_home_current.html', 'w', encoding='utf-8') as f: f.write(html) print("Success.")