diff --git a/src/update_solution.py b/src/update_solution.py index d4e5d76b..bd1bddc7 100644 --- a/src/update_solution.py +++ b/src/update_solution.py @@ -2,24 +2,23 @@ import json import sys import re +from datetime import datetime if __name__ == "__main__": - assert(len(sys.argv) == 4) # Adjusted to expect three arguments + the script name - handle = "Hunterdii" # The fixed GitHub user handle - token = sys.argv[1] - readmePath = sys.argv[2] + assert(len(sys.argv) == 4) + handle = sys.argv[1] # GitHub username (e.g., Hunterdii) + token = sys.argv[2] # GitHub token for authentication + readmePath = sys.argv[3] # Path to the README.md file headers = { "Authorization": f"token {token}" } - # Set the target repository to the specific repo - repo_name = "Hunterdii/GeeksforGeeks-POTD" - commit_url = f"https://api.github.com/repos/{repo_name}/commits?sha=main" - - # Fetch the latest commit details + # Correct the repo name and fetch the latest commit details from the correct repository + repo_name = "GeeksforGeeks-POTD" # Specify the correct repo name here + commit_url = f"https://api.github.com/repos/{handle}/{repo_name}/commits?sha=main" response = requests.get(commit_url, headers=headers) - + if response.status_code != 200: print(f"Error fetching commit details: {response.text}") sys.exit(1) @@ -29,23 +28,23 @@ commit_message = commit_data['commit']['message'] commit_date = commit_data['commit']['committer']['date'] - # Extract the question name or solution identifier from the commit message + # Extract the question name or solution identifier from the commit message (example: "01(Nov) Solution Name") solution_identifier = commit_message.split(":")[0] # Assuming commit message starts with the identifier - # Generate the badge URL dynamically based on the solution identifier + # Generate the badge URL dynamically based on the solution badge_url = f"https://img.shields.io/badge/Solution-{solution_identifier}-blue" - badge_link = f"[![Today's Solution]({badge_url})](https://github.com/{repo_name}/commit/{commit_sha})" + badge_link = f"[![Today's Solution]({badge_url})](https://github.com/{handle}/{repo_name}/commit/{commit_sha})" # Prepare the commit link - commit_link = f"Commit URL: https://github.com/{repo_name}/commit/{commit_sha}" + commit_link = f"Commit URL: https://github.com/{handle}/{repo_name}/commit/{commit_sha}" # Update README with the new commit and badge with open(readmePath, "r") as readme: content = readme.read() # Update the commit link and the badge in the README file - new_content = re.sub(r"(?<=)[\s\S]*(?=)", f" {commit_link} ", content) - new_content = re.sub(r"(?<=)[\s\S]*(?=)", f" {badge_link} ", new_content) + new_content = re.sub(r"(?<=)[\s\S]*(?=)", commit_link, content) + new_content = re.sub(r"(?<=)[\s\S]*(?=)", badge_link, new_content) # Write the updated content back to README with open(readmePath, "w") as readme: