Skip to content

Commit adef416

Browse files
authored
Create update_readme.py
1 parent e3cb42e commit adef416

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

.github/scripts/update_readme.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import os
2+
from datetime import datetime
3+
import subprocess
4+
5+
README_PATH = "README.md"
6+
7+
# Count problems
8+
def count_problems():
9+
count = 0
10+
for folder in ["Easy", "Medium", "Hard"]:
11+
if os.path.exists(folder):
12+
for file in os.listdir(folder):
13+
if os.path.isfile(os.path.join(folder, file)):
14+
count += 1
15+
return count
16+
17+
# Get last commit date
18+
def last_updated():
19+
result = subprocess.run(
20+
["git", "log", "-1", "--format=%cd", "--date=iso"],
21+
capture_output=True,
22+
text=True
23+
)
24+
return result.stdout.strip()
25+
26+
def update_readme():
27+
with open(README_PATH, "r", encoding="utf-8") as f:
28+
content = f.read()
29+
30+
problems_count = count_problems()
31+
updated_time = last_updated()
32+
33+
content = content.replace(
34+
"Problems solved: <!--PROBLEMS_COUNT-->",
35+
f"Problems solved: {problems_count}"
36+
)
37+
content = content.replace(
38+
"Last updated: <!--LAST_UPDATED-->",
39+
f"Last updated: {updated_time}"
40+
)
41+
42+
with open(README_PATH, "w", encoding="utf-8") as f:
43+
f.write(content)
44+
45+
if __name__ == "__main__":
46+
update_readme()

0 commit comments

Comments
 (0)