Skip to content

Commit 144d6ed

Browse files
authored
Update update_solution.py
1 parent 8b2f405 commit 144d6ed

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/update_solution.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import sys
44
import re
5+
from datetime import datetime
56

67
if __name__ == "__main__":
78
assert(len(sys.argv) == 4)
@@ -13,26 +14,24 @@
1314
"Authorization": f"token {token}"
1415
}
1516

16-
# Get the latest commit details
17-
repo_name = "Hunterdii/GeeksforGeeks-POTD" # Correct repo
18-
commit_url = f"https://api.github.com/repos/{repo_name}/commits?sha=main"
17+
# Correct repository name
18+
repo_name = "Hunterdii/GeeksforGeeks-POTD"
1919

20-
# Make the request to fetch the latest commit
20+
# Get the latest commit details for the correct repository
21+
commit_url = f"https://api.github.com/repos/{repo_name}/commits?sha=main"
2122
response = requests.get(commit_url, headers=headers)
2223

2324
if response.status_code != 200:
2425
print(f"Error fetching commit details: {response.text}")
2526
sys.exit(1)
2627

27-
# Parse the response JSON to get commit details
2828
commit_data = response.json()[0]
2929
commit_sha = commit_data['sha']
3030
commit_message = commit_data['commit']['message']
3131
commit_date = commit_data['commit']['committer']['date']
3232

33-
# Extract the question name or solution identifier from the commit message
34-
# Assuming commit message starts with the identifier, like "01(Nov) Solution Name"
35-
solution_identifier = commit_message.split(":")[0]
33+
# Extract the question name or solution identifier from the commit message (e.g., "01(Nov) Solution Name")
34+
solution_identifier = commit_message.split(":")[0] # Assuming commit message starts with the identifier
3635

3736
# Generate the badge URL dynamically based on the solution
3837
badge_url = f"https://img.shields.io/badge/Solution-{solution_identifier}-blue"
@@ -46,8 +45,8 @@
4645
content = readme.read()
4746

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

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

0 commit comments

Comments
 (0)