-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcount.py
More file actions
71 lines (49 loc) · 1.47 KB
/
Copy pathcount.py
File metadata and controls
71 lines (49 loc) · 1.47 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
from pathlib import Path
# 문제 풀이 저장소 루트
ROOT = Path(__file__).resolve().parent
# 문제 폴더가 아닌 디렉터리
EXCLUDE_DIRS = {
".git",
".github",
"scripts",
"templates",
}
def count_problems(root: Path) -> dict[str, int]:
"""
README.md가 존재하는 디렉터리를 문제 풀이 1개로 계산한다.
반환값:
{
"Baekjoon": 123,
"Programmers": 45,
...
}
"""
counts = {}
for platform_dir in root.iterdir():
if not platform_dir.is_dir():
continue
if platform_dir.name in EXCLUDE_DIRS:
continue
count = 0
for readme in platform_dir.rglob("README.md"):
# .git 등의 디렉터리 내부는 제외
if any(part in EXCLUDE_DIRS for part in readme.parts):
continue
count += 1
if count > 0:
counts[platform_dir.name] = count
return counts
def main():
counts = count_problems(ROOT)
total = sum(counts.values())
print("================================")
print(" Algorithm Problem Count")
print("================================")
for platform, count in sorted(counts.items()):
print(f"{platform:<20} {count:>5}")
print("--------------------------------")
print(f"{'TOTAL':<20} {total:>5}")
print("================================")
if __name__ == "__main__":
main()