format_index.py 855 B

1234567891011121314151617181920212223242526272829
  1. import math
  2. rowdivs = ["""<div class="6u 12u$(xsmall)">\n""",
  3. """<div class="6u$ 12u$(xsmall)">\n"""]
  4. def make_row(*divs):
  5. row = """<div class="row 150%">\n"""
  6. for i, div in enumerate(divs):
  7. row += rowdivs[i] + div + "</div>\n"
  8. row += """</div>\n"""
  9. return row
  10. if __name__ == "__main__":
  11. with open("listofdivs.template", "r") as f:
  12. list_of_divs = f.read().split("==========")
  13. n_cells = len(list_of_divs)
  14. n_cols = 2
  15. n_rows = math.ceil(n_cells / n_cols)
  16. content = ""
  17. for i in range(n_rows):
  18. cells = list_of_divs[i*n_cols:(i+1)*n_cols]
  19. content += make_row(*cells)
  20. with open("index.template", "r") as f:
  21. index_template = f.read()
  22. index = index_template.replace("__TEMPLATE_STRING__", content)
  23. with open("index.html", "w") as f:
  24. f.write(index)