import urllib from .const import * # dead simple template engine def render_page(template: str, **kwargs): page = template for k, v in kwargs.items(): page = page.replace(f"%{str(k)}%", str(v)) return page def render_sites(sites: list, columns=8, rows=4, action="go"): top_sites = sorted(sites, key=lambda s: int(s[VISITS]), reverse=True)[ : (columns * rows) # top col*row sites, default=32 ] # site_rows: group sites into rows if len(top_sites) < 32: top_sites.extend([None] * (32 - len(top_sites))) site_rows = list(zip(*[top_sites[n::columns] for n in range(columns)])) html = '
{col[TITLE]}
' + "