Skip to content

Commit 2f677c9

Browse files
authored
Update update_readme.py
1 parent 54143c6 commit 2f677c9

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

.github/scripts/update_readme.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,42 @@
11
import os
22
from datetime import datetime
3-
from zoneinfo import ZoneInfo # Built-in in Python 3.9+
4-
import re
3+
import subprocess
54

65
README_PATH = "README.md"
76

8-
# Count only .java files inside Easy, Medium, Hard (recursive)
7+
# Count problems
98
def count_problems():
109
count = 0
1110
for folder in ["Easy", "Medium", "Hard"]:
1211
if os.path.exists(folder):
13-
for root, _, files in os.walk(folder):
14-
for file in files:
15-
if file.endswith(".java"):
16-
count += 1
12+
for file in os.listdir(folder):
13+
if os.path.isfile(os.path.join(folder, file)):
14+
count += 1
1715
return count
1816

19-
# Get current IST time in human-readable format
17+
# Get last commit date
2018
def last_updated():
21-
ist_time = datetime.now(ZoneInfo("Asia/Kolkata"))
22-
return ist_time.strftime("%d %b %Y, %I:%M %p IST")
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()
2325

24-
# Update README.md placeholders
2526
def update_readme():
2627
with open(README_PATH, "r", encoding="utf-8") as f:
2728
content = f.read()
2829

2930
problems_count = count_problems()
3031
updated_time = last_updated()
3132

32-
# Use regex to ensure replacement works even if extra spaces
33-
content = re.sub(
34-
r"Problems solved: <!--PROBLEMS_COUNT-->.*",
35-
f"Problems solved: <!--PROBLEMS_COUNT-->{problems_count}",
36-
content
33+
content = content.replace(
34+
"Problems solved: <!--PROBLEMS_COUNT-->",
35+
f"Problems solved: {problems_count}"
3736
)
38-
content = re.sub(
39-
r"Last updated: <!--LAST_UPDATED-->.*",
40-
f"Last updated: <!--LAST_UPDATED-->{updated_time}",
41-
content
37+
content = content.replace(
38+
"Last updated: <!--LAST_UPDATED-->",
39+
f"Last updated: {updated_time}"
4240
)
4341

4442
with open(README_PATH, "w", encoding="utf-8") as f:

0 commit comments

Comments
 (0)