Skip to content

Commit 7964888

Browse files
authored
Update update_commit.py
1 parent 36f0613 commit 7964888

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/update_commit.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
day_of_month = today.strftime("%d") # Get current day of the month (e.g., 06)
1919
month = today.strftime("%b") # Get current month (e.g., Nov)
2020

21-
# Generate the filename based on the day of the month (e.g., 06(Nov) Root to leaf paths sum.md)
22-
today_solution_filename = f"{day_of_month}({month})" # The pattern that matches the filename format.
21+
# Prepare the solution filename for today (e.g., 06(Nov) Root to leaf paths sum.md)
22+
today_solution_filename = f"{day_of_month}({month}) Root to leaf paths sum.md"
2323

2424
# Make a request to GitHub to list files in the directory
2525
dir_url = f"https://api.github.com/repos/{repository}/contents/{month}%202024%20GFG%20SOLUTION"
@@ -31,26 +31,24 @@
3131

3232
files = response.json()
3333

34-
# Check if files are empty or response is not valid
35-
if isinstance(files, dict) and files.get('message') == 'Not Found':
34+
# Check if the directory exists or if there are any issues
35+
if isinstance(files, dict) and 'message' in files and files['message'] == 'Not Found':
3636
print(f"Directory not found: {dir_url}")
3737
sys.exit(1)
3838

39-
# Search for the correct file based on the date
39+
# Now, we try to find the solution file for today
4040
today_file = None
4141
for file in files:
42-
if file['name'].startswith(today_solution_filename):
42+
if file['name'].startswith(f"{day_of_month}({month})"):
4343
today_file = file['name']
4444
break
4545

4646
if not today_file:
47-
print(f"No solution file found for {today_solution_filename}. Please check the directory.")
47+
print(f"Solution file for {today_solution_filename} not found.")
4848
sys.exit(1)
4949

50-
# Prepare the correct file URL based on the found filename
51-
solution_url = f"https://github.com/{repository}/blob/main/{month}%202024%20GFG%20SOLUTION/{today_file}"
52-
5350
# Prepare the badge URL with the correct link to today's solution
51+
solution_url = f"https://github.com/{repository}/blob/main/{month}%202024%20GFG%20SOLUTION/{today_file}"
5452
badge_url = "https://img.shields.io/badge/GeeksforGeeks-Solution%20of%20the%20Day-blue"
5553
badge_link = f"[![Today's POTD Solution]({badge_url})]({solution_url})"
5654

0 commit comments

Comments
 (0)