Skip to content

Commit 122fb68

Browse files
authored
Update update_commit.py
1 parent 343ae3a commit 122fb68

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

src/update_commit.py

+10-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import requests
22
import sys
33
import re
4+
from datetime import datetime
45

56
if __name__ == "__main__":
67
assert(len(sys.argv) == 4)
@@ -12,33 +13,26 @@
1213
"Authorization": f"token {token}"
1314
}
1415

15-
# Get the latest commit of the day for the repository
16-
commit_url = f"https://api.github.com/repos/{repository}/commits"
17-
response = requests.get(commit_url, headers=headers)
16+
# Get the current date
17+
today = datetime.today()
18+
day_of_month = today.strftime("%d") # Get current day of the month
19+
month = today.strftime("%b") # Get current month (e.g., Nov)
1820

19-
if not response.ok:
20-
print(f"Failed to fetch commits: {response.status_code} {response.text}")
21-
sys.exit(1)
22-
23-
commits = response.json()
24-
25-
# Assuming the first commit in the list is the most recent commit
26-
latest_commit = commits[0]
27-
commit_sha = latest_commit['sha']
28-
commit_link = f"https://github.com/{repository}/commit/{commit_sha}"
21+
# Format the solution file name for today (e.g., 07(Nov)Next Problem.md)
22+
today_solution_filename = f"{day_of_month}({month}){today.strftime('%A')}.md"
2923

3024
# Prepare the badge URL and commit link to update README
3125
badge_url = "https://img.shields.io/badge/GeeksforGeeks-Solution%20of%20the%20Day-blue"
32-
badge_link = f"[![Today's POTD Solution]({badge_url})](https://github.com/{repository})"
26+
badge_link = f"[![Today's POTD Solution]({badge_url})](https://github.com/{repository}/blob/main/{month}%202024%20GFG%20SOLUTION/{today_solution_filename})"
3327

3428
# Read the README file and update the sections for commit and badge
3529
with open(readme_path, "r") as readme:
3630
content = readme.read()
3731

38-
# Update commit link
32+
# Update today's solution link
3933
content = re.sub(
4034
r"(?<=<!--START_SECTION:latest-commit-->).*?(?=<!--END_SECTION:latest-commit-->)",
41-
f"\n{commit_link}\n",
35+
f"\nhttps://github.com/{repository}/blob/main/{month}%202024%20GFG%20SOLUTION/{today_solution_filename}\n",
4236
content,
4337
flags=re.DOTALL
4438
)

0 commit comments

Comments
 (0)