Skip to content

Commit d5dc5cf

Browse files
authored
Update update_solution.py
1 parent 4e5488d commit d5dc5cf

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/update_solution.py

+15-16
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,23 @@
22
import json
33
import sys
44
import re
5+
from datetime import datetime
56

67
if __name__ == "__main__":
7-
assert(len(sys.argv) == 4) # Adjusted to expect three arguments + the script name
8-
handle = "Hunterdii" # The fixed GitHub user handle
9-
token = sys.argv[1]
10-
readmePath = sys.argv[2]
8+
assert(len(sys.argv) == 4)
9+
handle = sys.argv[1] # GitHub username (e.g., Hunterdii)
10+
token = sys.argv[2] # GitHub token for authentication
11+
readmePath = sys.argv[3] # Path to the README.md file
1112

1213
headers = {
1314
"Authorization": f"token {token}"
1415
}
1516

16-
# Set the target repository to the specific repo
17-
repo_name = "Hunterdii/GeeksforGeeks-POTD"
18-
commit_url = f"https://api.github.com/repos/{repo_name}/commits?sha=main"
19-
20-
# Fetch the latest commit details
17+
# Correct the repo name and fetch the latest commit details from the correct repository
18+
repo_name = "GeeksforGeeks-POTD" # Specify the correct repo name here
19+
commit_url = f"https://api.github.com/repos/{handle}/{repo_name}/commits?sha=main"
2120
response = requests.get(commit_url, headers=headers)
22-
21+
2322
if response.status_code != 200:
2423
print(f"Error fetching commit details: {response.text}")
2524
sys.exit(1)
@@ -29,23 +28,23 @@
2928
commit_message = commit_data['commit']['message']
3029
commit_date = commit_data['commit']['committer']['date']
3130

32-
# Extract the question name or solution identifier from the commit message
31+
# Extract the question name or solution identifier from the commit message (example: "01(Nov) Solution Name")
3332
solution_identifier = commit_message.split(":")[0] # Assuming commit message starts with the identifier
3433

35-
# Generate the badge URL dynamically based on the solution identifier
34+
# Generate the badge URL dynamically based on the solution
3635
badge_url = f"https://img.shields.io/badge/Solution-{solution_identifier}-blue"
37-
badge_link = f"[![Today's Solution]({badge_url})](https://github.com/{repo_name}/commit/{commit_sha})"
36+
badge_link = f"[![Today's Solution]({badge_url})](https://github.com/{handle}/{repo_name}/commit/{commit_sha})"
3837

3938
# Prepare the commit link
40-
commit_link = f"Commit URL: https://github.com/{repo_name}/commit/{commit_sha}"
39+
commit_link = f"Commit URL: https://github.com/{handle}/{repo_name}/commit/{commit_sha}"
4140

4241
# Update README with the new commit and badge
4342
with open(readmePath, "r") as readme:
4443
content = readme.read()
4544

4645
# Update the commit link and the badge in the README file
47-
new_content = re.sub(r"(?<=<!--START_SECTION:latest-commit-->)[\s\S]*(?=<!--END_SECTION:latest-commit-->)", f" {commit_link} ", content)
48-
new_content = re.sub(r"(?<=<!--START_SECTION:potd-badge-->)[\s\S]*(?=<!--END_SECTION:potd-badge-->)", f" {badge_link} ", new_content)
46+
new_content = re.sub(r"(?<=<!--START_SECTION:latest-commit-->)[\s\S]*(?=<!--END_SECTION:latest-commit-->)", commit_link, content)
47+
new_content = re.sub(r"(?<=<!--START_SECTION:potd-badge-->)[\s\S]*(?=<!--END_SECTION:potd-badge-->)", badge_link, new_content)
4948

5049
# Write the updated content back to README
5150
with open(readmePath, "w") as readme:

0 commit comments

Comments
 (0)