代码拉取完成,页面将自动刷新
import re
import os
from string import Template
with open("readme_template.md") as readme_file:
readme = readme_file.read()
codes = re.findall(r'\$code_([^\s]*)', readme)
demos = re.findall(r'\$demo_([^\s]*)', readme)
template_dict = {}
for code_src in codes:
with open(os.path.join("demo", code_src + ".py")) as code_file:
python_code = code_file.read()
python_code = python_code.replace('if __name__ == "__main__":\n iface.launch()', "iface.launch()")
if python_code.startswith("# Demo"):
python_code = "\n".join(python_code.split("\n")[2:])
template_dict["code_" + code_src] = "```python\n" + python_code + "\n```"
for demo_src in demos:
template_dict["demo_" + demo_src] = "![" + demo_src + " interface](demo/screenshots/" + demo_src + "/1.gif)"
readme_template = Template(readme)
output_readme = readme_template.substitute(template_dict)
with open("README.md", "w") as readme_md:
readme_md.write(output_readme)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。