-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.py
More file actions
41 lines (33 loc) · 1.26 KB
/
check.py
File metadata and controls
41 lines (33 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 解答のマークダウンを読み込んで解答済みの問題を抽出するスクリプト
# CSV形式で出力するため、`check.py > result.csv` のように実行してください
#
import glob
import os
import re
def main():
result = dict()
files = glob.glob(os.path.join(os.getcwd(), "articles", "*.md"))
for file in files:
if not os.path.isfile(file):
continue
with open(file, "r", encoding="UTF-8") as f:
content = f.read()
f.close()
pattern = r"- 🔗\[(.*)\]\((.*)\)\n"
m = re.search(pattern, content)
if m:
t = m.group(1).split(" - ")[0].strip()
titles = t.split(" ")
key = titles[0]
submission = titles[1] if len(titles) > 1 else ""
result.setdefault(key, []).append(
f'"{submission}"' if submission else ""
)
result = dict(sorted(result.items()))
for key, submissions in result.items():
if len(submissions) > 1:
submissions = list(set(submissions))
submissions.sort()
print(f'"{key}", {", ".join(submissions)}')
if __name__ == "__main__":
main()