-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_html.py
30 lines (23 loc) · 898 Bytes
/
generate_html.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from os.path import exists
from xml.etree import ElementTree as ET
def generate_html_page(filename, div_children):
"""
:param filename: the html filename that will be generated
:param div_children: Number of divs to be added to the body of the html page, along with the span element
:return: None
"""
file_name = f'static_dir/{filename}.html'
# Uncomment this to not overwrite the file each time
# if exists(file_name):
# return
html = ET.Element('html')
body = ET.Element('body')
html.append(body)
span = ET.Element('span', attrib={'class': 'bar'})
body.append(span)
span.text = "Hello World"
for idx in range(div_children):
div = ET.Element('div', attrib={'class': f'foo{idx}'})
body.append(div)
with open(file_name, 'w') as f:
ET.ElementTree(html).write(f, encoding='unicode', method='html')