Skip to content

Commit 969b84c

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

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

src/update_solution.py

+6-15
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@
1414
"Authorization": f"token {token}"
1515
}
1616

17-
# Specify the correct repository here for commit fetching
17+
# Get the latest commit details
1818
repo_name = "Hunterdii/GeeksforGeeks-POTD" # Correct repo
1919
commit_url = f"https://api.github.com/repos/{repo_name}/commits?sha=main"
20-
21-
# Fetch the latest commit for the correct repo
22-
response = requests.get(commit_url, headers=headers)
20+
2321

2422
if response.status_code != 200:
2523
print(f"Error fetching commit details: {response.text}")
@@ -29,19 +27,16 @@
2927
commit_sha = commit_data['sha']
3028
commit_message = commit_data['commit']['message']
3129
commit_date = commit_data['commit']['committer']['date']
32-
30+
3331
# Extract the question name or solution identifier from the commit message (example: "01(Nov) Solution Name")
3432
solution_identifier = commit_message.split(":")[0] # Assuming commit message starts with the identifier
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-
33+
3934
# Generate the badge URL dynamically based on the solution
4035
badge_url = f"https://img.shields.io/badge/Solution-{solution_identifier}-blue"
4136
badge_link = f"[![Today's Solution]({badge_url})](https://github.com/{handle}/{sys.argv[1]}/commit/{commit_sha})"
4237

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

4641
# Update README with the new commit and badge
4742
with open(readmePath, "r") as readme:
@@ -55,8 +50,4 @@
5550
with open(readmePath, "w") as readme:
5651
readme.write(new_content)
5752

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}.")
53+
print("Successfully updated README with the latest commit and badge.")

0 commit comments

Comments
 (0)