11import os
22import subprocess
33from datetime import datetime
4+ import re
45
56README_PATH = "README.md"
67
7- # Count problems
8+ # Count problems (only .java files, recursively)
89def count_problems ():
910 count = 0
1011 for folder in ["Easy" , "Medium" , "Hard" ]:
1112 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
13+ for root , _ , files in os .walk (folder ):
14+ for file in files :
15+ if file .endswith (".java" ):
16+ count += 1
1517 return count
1618
17- # Get last commit date (latest in repo)
19+ # Get last commit date of the repo
1820def last_updated ():
1921 result = subprocess .run (
2022 ["git" , "log" , "-1" , "--format=%cd" , "--date=iso" ],
2123 capture_output = True ,
2224 text = True
2325 )
24- # Convert to human readable format
25- dt = datetime .fromisoformat (result .stdout .strip ())
26- return dt .strftime ("%d %b %Y, %I:%M %p IST" )
26+ raw_date = result .stdout .strip ()
27+ try :
28+ dt = datetime .fromisoformat (raw_date .replace (" " , "T" , 1 ))
29+ except ValueError :
30+ # Fallback: parse with strptime
31+ dt = datetime .strptime (raw_date , "%Y-%m-%d %H:%M:%S %z" )
32+ return dt .strftime ("%d %b %Y, %I:%M %p %Z" )
2733
2834def update_readme ():
2935 with open (README_PATH , "r" , encoding = "utf-8" ) as f :
@@ -32,13 +38,12 @@ def update_readme():
3238 problems_count = count_problems ()
3339 updated_time = last_updated ()
3440
35- # Replace only inside the Progress section
36- import re
41+ # Regex to replace only inside the Progress section
42+ new_progress = f"## 🏆 Progress \n \n - Problems solved: { problems_count } \n - Last updated: { updated_time } "
3743 content = re .sub (
38- r"( ## 🏆 Progress\s+Problems solved:).* " ,
39- f"## 🏆 Progress \n \n Problems solved: { problems_count } \n Last updated: { updated_time } " ,
44+ r"## 🏆 Progress\s+(- Problems solved: .*?\n- Last updated: .*) " ,
45+ new_progress ,
4046 content ,
41- count = 1 ,
4247 flags = re .DOTALL
4348 )
4449
0 commit comments