From 79648883ec77a859381764b8479bded04934e9d3 Mon Sep 17 00:00:00 2001 From: Het Patel <124852522+Hunterdii@users.noreply.github.com> Date: Wed, 6 Nov 2024 23:13:06 +0530 Subject: [PATCH] Update update_commit.py --- src/update_commit.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/update_commit.py b/src/update_commit.py index c8cd5c7a..aaf2ad4e 100644 --- a/src/update_commit.py +++ b/src/update_commit.py @@ -18,8 +18,8 @@ day_of_month = today.strftime("%d") # Get current day of the month (e.g., 06) month = today.strftime("%b") # Get current month (e.g., Nov) - # Generate the filename based on the day of the month (e.g., 06(Nov) Root to leaf paths sum.md) - today_solution_filename = f"{day_of_month}({month})" # The pattern that matches the filename format. + # Prepare the solution filename for today (e.g., 06(Nov) Root to leaf paths sum.md) + today_solution_filename = f"{day_of_month}({month}) Root to leaf paths sum.md" # Make a request to GitHub to list files in the directory dir_url = f"https://api.github.com/repos/{repository}/contents/{month}%202024%20GFG%20SOLUTION" @@ -31,26 +31,24 @@ files = response.json() - # Check if files are empty or response is not valid - if isinstance(files, dict) and files.get('message') == 'Not Found': + # Check if the directory exists or if there are any issues + if isinstance(files, dict) and 'message' in files and files['message'] == 'Not Found': print(f"Directory not found: {dir_url}") sys.exit(1) - # Search for the correct file based on the date + # Now, we try to find the solution file for today today_file = None for file in files: - if file['name'].startswith(today_solution_filename): + if file['name'].startswith(f"{day_of_month}({month})"): today_file = file['name'] break if not today_file: - print(f"No solution file found for {today_solution_filename}. Please check the directory.") + print(f"Solution file for {today_solution_filename} not found.") sys.exit(1) - # Prepare the correct file URL based on the found filename - solution_url = f"https://github.com/{repository}/blob/main/{month}%202024%20GFG%20SOLUTION/{today_file}" - # Prepare the badge URL with the correct link to today's solution + solution_url = f"https://github.com/{repository}/blob/main/{month}%202024%20GFG%20SOLUTION/{today_file}" badge_url = "https://img.shields.io/badge/GeeksforGeeks-Solution%20of%20the%20Day-blue" badge_link = f"[![Today's POTD Solution]({badge_url})]({solution_url})"