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 68ec746 commit fc0b786
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/update_commit.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@

import requests
import sys
import re
from datetime import datetime

if __name__ == "__main__":
assert(len(sys.argv) == 5)
assert(len(sys.argv) == 4)
repository = sys.argv[1]
token = sys.argv[2]
readme_path = sys.argv[3]
file_name = sys.argv[4] # The filename is now passed dynamically

# Get the current date
today = datetime.today()
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 URL for today (dynamically from the file_name)
solution_url = f"https://github.com/{repository}/blob/main/November%202024%20GFG%20SOLUTION/{file_name}"
# Prepare the solution filename for today (e.g., 06(Nov)Root to leaf paths sum.md)
today_solution_filename = f"{day_of_month}({month}){today.strftime('%A')}.md"

# Prepare the commit URL for today (we don't need to change this as it will be dynamically picked from the latest commit)
solution_url = f"https://github.com/{repository}/blob/main/{month}%202024%20GFG%20SOLUTION/{today_solution_filename}"

# Prepare the badge URL and commit link to update README
badge_url = "https://img.shields.io/badge/GeeksforGeeks-Solution%20of%20the%20Day-blue"
Expand All @@ -26,6 +29,14 @@
with open(readme_path, "r") as readme:
content = readme.read()

# Update today's solution link (for the commit)
# content = re.sub(
# r"(?<=<!--START_SECTION:latest-commit-->).*?(?=<!--END_SECTION:latest-commit-->)",
# f"\n{solution_url}\n",
# content,
# flags=re.DOTALL
# )

# Update badge link
content = re.sub(
r"(?<=<!--START_SECTION:potd-badge-->).*?(?=<!--END_SECTION:potd-badge-->)",
Expand Down

0 comments on commit fc0b786

Please sign in to comment.