[scripts/supportedsites] update 'generate_output()'

use f-strings etc
This commit is contained in:
Mike Fährmann
2025-08-13 16:12:33 +02:00
parent ef635635c1
commit 8f67dd347b

View File

@@ -682,52 +682,50 @@ COLUMNS = (
def generate_output(columns, categories, domains):
thead = []
append = thead.append
append("<tr>")
thead.append("<tr>")
for column in columns:
append(" <th>" + column[0] + "</th>")
append("</tr>")
thead.append(f" <th>{column[0]}</th>")
thead.append("</tr>")
tbody = []
append = tbody.append
for bcat, base in categories.items():
if bcat and base:
name = BASE_MAP.get(bcat) or (bcat.capitalize() + " Instances")
append('\n<tr>\n <td colspan="4"><strong>' +
name + '</strong></td>\n</tr>')
tbody.append(f"""
<tr>
<td colspan="4"><strong>{name}</strong></td>
</tr>\
""")
clist = base.items()
else:
clist = sorted(base.items(), key=category_key)
for category, subcategories in clist:
append("<tr>")
tbody.append("<tr>")
for column in columns:
domain = domains[category]
content = column[2](bcat, category, subcategories, domain)
append(" <td>" + content + "</td>")
append("</tr>")
tbody.append(f" <td>{content}</td>")
tbody.append("</tr>")
TEMPLATE = """# Supported Sites
NL = "\n"
GENERATOR = "/".join(os.path.normpath(__file__).split(os.sep)[-2:])
return f"""\
# Supported Sites
<!-- auto-generated by {} -->
<!-- auto-generated by {GENERATOR} -->
Consider all listed sites to potentially be NSFW.
<table>
<thead valign="bottom">
{}
{NL.join(thead)}
</thead>
<tbody valign="top">
{}
{NL.join(tbody)}
</tbody>
</table>
"""
return TEMPLATE.format(
"/".join(os.path.normpath(__file__).split(os.sep)[-2:]),
"\n".join(thead),
"\n".join(tbody),
)
categories, domains = build_extractor_list()