Skip to content

Commit 80ebc81

Browse files
authored
Update update_solution.py
1 parent 969b84c commit 80ebc81

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/update_solution.py

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

76
if __name__ == "__main__":
87
assert(len(sys.argv) == 4)
@@ -18,33 +17,37 @@
1817
repo_name = "Hunterdii/GeeksforGeeks-POTD" # Correct repo
1918
commit_url = f"https://api.github.com/repos/{repo_name}/commits?sha=main"
2019

20+
# Make the request to fetch the latest commit
21+
response = requests.get(commit_url, headers=headers)
2122

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

27+
# Parse the response JSON to get commit details
2628
commit_data = response.json()[0]
2729
commit_sha = commit_data['sha']
2830
commit_message = commit_data['commit']['message']
2931
commit_date = commit_data['commit']['committer']['date']
3032

31-
# Extract the question name or solution identifier from the commit message (example: "01(Nov) Solution Name")
32-
solution_identifier = commit_message.split(":")[0] # Assuming commit message starts with the identifier
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]
3336

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

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

4144
# Update README with the new commit and badge
4245
with open(readmePath, "r") as readme:
4346
content = readme.read()
4447

4548
# Update the commit link and the badge in the README file
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)
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)
4851

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

0 commit comments

Comments
 (0)