import re
html_path = 'templates/backtest.html'
with open(html_path, 'r', encoding='utf-8') as f:
html = f.read()
# Pattern for EOD block
# 1.
... id="PREFIX_eod_enabled" ...
# 2.
... id="PREFIX_eod_hm" ...
regex = re.compile(
r'(\s*
\s*
\s*]*>\s*\s*
\s*
\s*
\s*\s*]*>\s*
)',
re.DOTALL
)
def replacer(match):
original_text = match.group(1)
prefix = match.group(2)
# We will remove it from its original place and append it after the row closes, but wait, the regex matches it exactly.
# It's better to just return empty string, and insert the new block after the end of the current .row.
# But wait, how do we insert it after the row?
return f"" + original_text
html = regex.sub(replacer, html)
with open(html_path, 'w', encoding='utf-8') as f:
f.write(html)
print("done")