29 lines
1.2 KiB
Python
29 lines
1.2 KiB
Python
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. <div class="col-auto d-flex align-items-end"> ... id="PREFIX_eod_enabled" ... </div>
|
|
# 2. <div class="..."> ... id="PREFIX_eod_hm" ... </div>
|
|
|
|
regex = re.compile(
|
|
r'(\s*<div class="col-auto d-flex align-items-end">\s*<div class="form-check mb-2">\s*<input class="form-check-input" type="checkbox" id="([a-z]+)_eod_enabled"[^>]*>\s*<label[^>]*for="\2_eod_enabled"[^>]*>EOD청산</label>\s*</div>\s*</div>\s*<div class="[^"]*">\s*<label class="form-label param-row"[^>]*>EOD시각.*?</label>\s*<input type="text" class="form-control" id="\2_eod_hm"[^>]*>\s*</div>)',
|
|
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"<!-- EOD_BLOCK_{prefix} -->" + original_text
|
|
|
|
html = regex.sub(replacer, html)
|
|
|
|
with open(html_path, 'w', encoding='utf-8') as f:
|
|
f.write(html)
|
|
print("done")
|