Skip to content

Commit 996fede

Browse files
authored
Update update_solution.py
1 parent dadf53c commit 996fede

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/update_solution.py

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

76
if __name__ == "__main__":
8-
assert(len(sys.argv) == 4)
9-
handle = sys.argv[1]
10-
token = sys.argv[2]
11-
readmePath = sys.argv[3]
7+
assert(len(sys.argv) == 3) # Adjusted to take only the token and README path
8+
token = sys.argv[1]
9+
readmePath = sys.argv[2]
1210

1311
headers = {
1412
"Authorization": f"token {token}"
1513
}
1614

17-
# Get the latest commit details
18-
commit_url = f"https://api.github.com/repos/{handle}/{sys.argv[1]}/commits?sha=main"
15+
# Set the target repository to the specific repo
16+
repo_name = "Hunterdii/GeeksforGeeks-POTD"
17+
commit_url = f"https://api.github.com/repos/{repo_name}/commits?sha=main"
18+
19+
# Fetch the latest commit details
1920
response = requests.get(commit_url, headers=headers)
20-
21+
2122
if response.status_code != 200:
2223
print(f"Error fetching commit details: {response.text}")
2324
sys.exit(1)
@@ -27,23 +28,23 @@
2728
commit_message = commit_data['commit']['message']
2829
commit_date = commit_data['commit']['committer']['date']
2930

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

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

3738
# Prepare the commit link
38-
commit_link = f"Commit URL: https://github.com/{handle}/{sys.argv[1]}/commit/{commit_sha}"
39+
commit_link = f"Commit URL: https://github.com/{repo_name}/commit/{commit_sha}"
3940

4041
# Update README with the new commit and badge
4142
with open(readmePath, "r") as readme:
4243
content = readme.read()
4344

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

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

0 commit comments

Comments
 (0)