| 4 | |
| 5 | |
| 6 | class HTML: |
| 7 | def __init__(self, web_dir, title, reflesh=0): |
| 8 | self.title = title |
| 9 | self.web_dir = web_dir |
| 10 | self.img_dir = os.path.join(self.web_dir, 'images') |
| 11 | if not os.path.exists(self.web_dir): |
| 12 | os.makedirs(self.web_dir) |
| 13 | if not os.path.exists(self.img_dir): |
| 14 | os.makedirs(self.img_dir) |
| 15 | # print(self.img_dir) |
| 16 | |
| 17 | self.doc = dominate.document(title=title) |
| 18 | if reflesh > 0: |
| 19 | with self.doc.head: |
| 20 | meta(http_equiv="reflesh", content=str(reflesh)) |
| 21 | |
| 22 | def get_image_dir(self): |
| 23 | return self.img_dir |
| 24 | |
| 25 | def add_header(self, str): |
| 26 | with self.doc: |
| 27 | h3(str) |
| 28 | |
| 29 | def add_table(self, border=1): |
| 30 | self.t = table(border=border, style="table-layout: fixed;") |
| 31 | self.doc.add(self.t) |
| 32 | |
| 33 | def add_images(self, ims, txts, links, width=400, height=0): |
| 34 | self.add_table() |
| 35 | with self.t: |
| 36 | with tr(): |
| 37 | for im, txt, link in zip(ims, txts, links): |
| 38 | with td(style="word-wrap: break-word;", halign="center", valign="top"): |
| 39 | with p(): |
| 40 | with a(href=os.path.join('images', link)): |
| 41 | if height != 0: |
| 42 | img(style="width:%dpx;height:%dpx" % (width, height), src=os.path.join('images', im)) |
| 43 | else: |
| 44 | img(style="width:%dpx" % (width), src=os.path.join('images', im)) |
| 45 | br() |
| 46 | p(txt) |
| 47 | |
| 48 | def save(self): |
| 49 | html_file = '%s/index.html' % self.web_dir |
| 50 | f = open(html_file, 'wt') |
| 51 | f.write(self.doc.render()) |
| 52 | f.close() |
| 53 | |
| 54 | |
| 55 | if __name__ == '__main__': |