refactor: format script (#112)
parent
50dac549e9
commit
8c5267e775
|
@ -6,3 +6,6 @@ indent_size = 2
|
|||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.py]
|
||||
indent_size = 4
|
||||
|
|
|
@ -1,61 +1,65 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import re
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
dire = ""
|
||||
|
||||
|
||||
def addSpace(x):
|
||||
print(x, end=" -> ")
|
||||
y = x[0]+" "+x[1]
|
||||
print(y)
|
||||
return(y)
|
||||
def add_space(origin: str):
|
||||
modified = "{} {}".format(origin[0], origin[1])
|
||||
print(repr(origin), "->", modified)
|
||||
return modified
|
||||
|
||||
|
||||
def changeDot(x):
|
||||
print(x, end=" -> ")
|
||||
y = x[0]+"."
|
||||
print(y)
|
||||
return(y)
|
||||
def change_dot(origin: str):
|
||||
modified = "{}.".format(origin)
|
||||
print(repr(origin), "->", modified)
|
||||
return modified
|
||||
|
||||
|
||||
def killSpace(x):
|
||||
print(x, end=" -> ")
|
||||
y = x.replace(" ", "")
|
||||
print(y)
|
||||
return(y)
|
||||
def remove_space(origin: str):
|
||||
modified = origin.replace(" ", "")
|
||||
print(repr(origin), "->", modified)
|
||||
return modified
|
||||
|
||||
|
||||
pass
|
||||
if len(sys.argv) < 2:
|
||||
dire = os.getcwd()
|
||||
print(dire)
|
||||
else:
|
||||
dire = sys.argv[1]
|
||||
print(dire)
|
||||
for root, dirs, files in os.walk(dire):
|
||||
for file in files:
|
||||
print(os.path.join(root, file))
|
||||
if file.split(".")[-1] == "md":
|
||||
f = open(os.path.join(root, file), "r", encoding="utf-8")
|
||||
content = f.read()
|
||||
f.close()
|
||||
content = re.sub("[0-9a-zA-Z][\|\u4e00-\u9fa5]",
|
||||
lambda x: addSpace(x.group(0)), content)
|
||||
content = re.sub("[\|\u4e00-\u9fa5][0-9a-zA-Z]",
|
||||
lambda x: addSpace(x.group(0)), content)
|
||||
content = re.sub("[0-9a-zA-Z%][。]",
|
||||
lambda x: changeDot(x.group(0)), content)
|
||||
content = re.sub("[,。;:?!”)] ",
|
||||
lambda x: killSpace(x.group(0)), content)
|
||||
content = re.sub(" [,。;:?!“(]",
|
||||
lambda x: killSpace(x.group(0)), content)
|
||||
def handle(full_path: str):
|
||||
print(full_path)
|
||||
with open(full_path, "r", encoding="utf-8") as fp:
|
||||
content = fp.read()
|
||||
content = re.sub(
|
||||
"[0-9a-zA-Z][|\u4e00-\u9fa5]", lambda x: add_space(x.group(0)), content
|
||||
)
|
||||
content = re.sub(
|
||||
"[|\u4e00-\u9fa5][0-9a-zA-Z]", lambda x: add_space(x.group(0)), content
|
||||
)
|
||||
content = re.sub("[0-9a-zA-Z%][。]", lambda x: change_dot(x.group(0)), content)
|
||||
content = re.sub("[,。;:?!”)] ", lambda x: remove_space(x.group(0)), content)
|
||||
content = re.sub(" [,。;:?!“(]", lambda x: remove_space(x.group(0)), content)
|
||||
content = re.sub("^[ ]+$", "", content)
|
||||
content = re.sub(" [Mm][Tt][Ff] ", " MtF ", content)
|
||||
content = re.sub(" [Ll][Gg][Bb][Tt] ", " LGBT ", content)
|
||||
content = re.sub(" [Qq][Qq] ", " QQ ", content)
|
||||
content = re.sub(" MtF ", " MtF ", content, flags=re.IGNORECASE)
|
||||
content = re.sub(" LGBT ", " LGBT ", content, flags=re.IGNORECASE)
|
||||
content = re.sub(" QQ ", " QQ ", content, flags=re.IGNORECASE)
|
||||
content = re.sub("\n\n\n", "\n\n", content)
|
||||
f = open(os.path.join(root, file), "w", encoding="utf-8")
|
||||
f.write(content)
|
||||
f.close()
|
||||
with open(full_path, "w", encoding="utf-8") as fp:
|
||||
fp.write(content)
|
||||
|
||||
|
||||
def walk_all_files(base: str):
|
||||
print(base)
|
||||
for root, dirs, files in os.walk(base):
|
||||
for file in files:
|
||||
full_path = os.path.join(root, file)
|
||||
full_path: str
|
||||
if full_path.endswith(".md"):
|
||||
handle(full_path)
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
walk_all_files(os.getcwd())
|
||||
else:
|
||||
walk_all_files(sys.argv[1])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
@ -9,12 +9,12 @@ on:
|
|||
|
||||
jobs:
|
||||
format:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-20.04
|
||||
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Format
|
||||
run: python3 .github/format.py content/zh-cn
|
||||
run: .github/format.py content/zh-cn
|
||||
- uses: EndBug/add-and-commit@v7
|
||||
with:
|
||||
author_name: mtfwikibot
|
||||
|
|
|
@ -650,7 +650,7 @@ PS:学校原则上禁止使用路由器和网络共享,但是可以偷偷用
|
|||
|
||||
## 清华大学
|
||||
|
||||
规模大概能有几十个人,但很多人并没有在各种 qq 群和微信群里紧密联系。由于有 purple 这个性少数社团,所以很容易能和一群友好的人们建立联系。总体环境不错。
|
||||
规模大概能有几十个人,但很多人并没有在各种 QQ 群和微信群里紧密联系。由于有 purple 这个性少数社团,所以很容易能和一群友好的人们建立联系。总体环境不错。
|
||||
|
||||
### 地理位置&交通设施
|
||||
|
||||
|
@ -1098,7 +1098,7 @@ G 组团比较特殊,貌似是公寓式宿舍。
|
|||
|
||||
### 院系探路
|
||||
|
||||
询问学姐可知,至少学生对性少数态度中立,不是人品问题不会排斥。当我问及:“学弟变学妹”,学姐没看懂,之后编者问“对 lgbt 团体的态度”。她解释“上一届有学弟就是,还已经找到男朋友了”。编者无法确定此话指 gay 还是 MtF 与男朋友。
|
||||
询问学姐可知,至少学生对性少数态度中立,不是人品问题不会排斥。当我问及:“学弟变学妹”,学姐没看懂,之后编者问“对 LGBT 团体的态度”。她解释“上一届有学弟就是,还已经找到男朋友了”。编者无法确定此话指 gay 还是 MtF 与男朋友。
|
||||
|
||||
### 编者自评
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ weight: 1
|
|||
|
||||
## 挂号
|
||||
|
||||
微信公众号 “北医三院服务号”- 导诊 - 预约挂号 - 外科 - 成型科门诊 - 周二 - 门诊号(易性症综合治疗门诊)
|
||||
微信公众号「北医三院服务号」-「导诊」-「预约挂号」-「外科」-「成型科门诊」-「周二」-「门诊号」(易性症综合治疗门诊)
|
||||
周日上午 7:00 准时放号,只需反复切换日期
|
||||
号较充足,一次 15 个左右,先抢先诊
|
||||
挂号费 50 元
|
||||
|
|
Loading…
Reference in New Issue