Skip to content

Commit 8337ca0

Browse files
authored
Update update_solution.py
1 parent 1da0230 commit 8337ca0

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/update_solution.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
"Authorization": f"token {token}"
1515
}
1616

17-
# Get the latest commit details
18-
commit_url = f"https://api.github.com/repos/{handle}/{sys.argv[1]}/commits?sha=main"
17+
# Specify the correct repository here for commit fetching
18+
repo_name = "Hunterdii/GeeksforGeeks-POTD" # Correct repo
19+
commit_url = f"https://api.github.com/repos/{repo_name}/commits?sha=main"
20+
21+
# Fetch the latest commit for the correct repo
1922
response = requests.get(commit_url, headers=headers)
2023

2124
if response.status_code != 200:
@@ -26,16 +29,19 @@
2629
commit_sha = commit_data['sha']
2730
commit_message = commit_data['commit']['message']
2831
commit_date = commit_data['commit']['committer']['date']
29-
32+
3033
# Extract the question name or solution identifier from the commit message (example: "01(Nov) Solution Name")
3134
solution_identifier = commit_message.split(":")[0] # Assuming commit message starts with the identifier
32-
35+
36+
# Define the daily solution file path (e.g., "01(Nov)question_name.md")
37+
solution_file_path = f"{solution_identifier}question_name.md"
38+
3339
# Generate the badge URL dynamically based on the solution
3440
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})"
41+
badge_link = f"[![Today's Solution]({badge_url})](https://github.com/{repo_name}/commit/{commit_sha})"
3642

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

4046
# Update README with the new commit and badge
4147
with open(readmePath, "r") as readme:
@@ -49,4 +55,8 @@
4955
with open(readmePath, "w") as readme:
5056
readme.write(new_content)
5157

52-
print("Successfully updated README with the latest commit and badge.")
58+
# Create or update the daily solution file (e.g., "01(Nov)question_name.md")
59+
with open(solution_file_path, "w") as solution_file:
60+
solution_file.write(f"# Solution for {solution_identifier}\n\nThis is the solution for {solution_identifier}. Commit link: [Commit]({commit_link})\n")
61+
62+
print(f"Successfully updated README with the latest commit, badge, and created {solution_file_path}.")

0 commit comments

Comments
 (0)