Skip to content

Commit

Permalink
Update update_commit.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Hunterdii authored Nov 6, 2024
1 parent 0488381 commit 8ed32b2
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/update_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,31 @@

# Get the current date
today = datetime.today()
day_of_month = today.strftime("%d") # Get current day of the month
month = today.strftime("%B") # Get current full month name (e.g., November)

# Format the solution file name for today (e.g., 06(Nov)Root to leaf paths sum.md)
today_solution_filename = f"{day_of_month}({today.strftime('%b')}){today.strftime('%A')}.md"
day_of_month = today.strftime("%d") # Get current day of the month (e.g., 06)
month = today.strftime("%b") # Get current month (e.g., Nov)

# Prepare the solution filename for today (e.g., 06(Nov)Root to leaf paths sum.md)
# You can customize this to the exact naming pattern you use
today_solution_filename = f"{day_of_month}({month}){today.strftime('%A')}.md"

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

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

# Update today's solution link in the README
# Update today's solution link (for the commit)
solution_url = f"https://github.com/{repository}/blob/main/{month}%202024%20GFG%20SOLUTION/{day_of_month}({month}){today.strftime('%A')}.md"
content = re.sub(
r"(?<=<!--START_SECTION:latest-commit-->).*?(?=<!--END_SECTION:latest-commit-->)",
f"\nhttps://github.com/{repository}/blob/main/{month}%202024%20GFG%20SOLUTION/{today_solution_filename}\n",
f"\n{solution_url}\n",
content,
flags=re.DOTALL
)

# Update the badge link
# Update badge link
content = re.sub(
r"(?<=<!--START_SECTION:potd-badge-->).*?(?=<!--END_SECTION:potd-badge-->)",
f"\n{badge_link}\n",
Expand Down

0 comments on commit 8ed32b2

Please sign in to comment.