This repository has been archived on 2026-08-27. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
RequestCounter/bin/core/length.py
T

29 lines
1.1 KiB
Python
Raw Normal View History

2022-02-05 16:45:35 +08:00
#!/usr/bin/env python3
# -- coding:utf-8 --
# @Author: markushammered@gmail.com
# @Development Tool: PyCharm
# @Create Time: 2022/2/5
# @File Name: length.py
2022-02-05 18:06:16 +08:00
def make_html(length: int, svg_width: int = 45, svg_height: int = 50) -> None:
2022-02-05 16:45:35 +08:00
"""
生成html
:param svg_height:
:param svg_width:
:param length:
:return:
"""
html_head = """<?xml version="1.0" encoding="UTF-8"?>
<svg width="%(w)s" height="%(h)s" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
2022-02-05 18:06:16 +08:00
<title>Flask Counter - {{ title }}</title>
2022-02-05 16:45:35 +08:00
<g>\n"""
svg_tag = """ <image x="%(x)s" y="0" width="%(w)s" height="%(h)s" xlink:href="{{ svg_img_%(i)s }}"></image>\n"""
html_feet = """</g></svg>"""
html_head = html_head % {'w': length * svg_width, 'h': svg_height} # 总体宽度
for i in range(length): # 拼接出完整的html
html_head += svg_tag % {'x': i * svg_width, 'w': svg_width, 'h': svg_height, 'i': i}
html_head += html_feet # 加上结尾标签
with open('./templates/index.html', 'w', encoding='utf-8') as template_fp: # 写入文件
template_fp.write(html_head)