代码拉取完成,页面将自动刷新
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import locale
meta = '''Title: My Document
Summary: A brief description of my document.
Authors: Waylan Limberg
Date: October 2, 2007
'''
def usage():
help = u'''Use new.py like:
new.py category title path-to-file
example:
new.py 深度截图 入门指南 deepin-shot/guide.md
it will create a file at "docs/deepin-shot/guide.md" with this content:
title:
category:首页
'''
print(help)
if __name__=="__main__":
if len(sys.argv)!= 4:
usage()
sys.exit(1)
encoding = locale.getdefaultlocale()[1]
meta = {}
category = sys.argv[1].decode(encoding, 'ignore')
title = sys.argv[2].decode(encoding, 'ignore')
file = sys.argv[3]
if not file.endswith(".md"):
print ("path-to-file must end with .md\n")
usage()
sys.exit(2)
meta["category"]=category
meta["title"]=title
mdmeta = "<!--Meta\n"
for k, v in meta.items():
mdmeta += k+":"+v+"\n"
mdmeta += "DO NOT Delete Meta Above -->\n"
path = "docs/" + file
try:
dir, name = os.path.split(path)
os.makedirs(dir)
except:
pass
fp = open(path, "w")
fp.writelines(mdmeta.encode('utf8', 'ignore'))
fp.close()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。