|
1 | 1 | import requests
|
2 | 2 | import sys
|
3 | 3 | import re
|
| 4 | +from datetime import datetime |
4 | 5 |
|
5 | 6 | if __name__ == "__main__":
|
6 | 7 | assert(len(sys.argv) == 4)
|
|
12 | 13 | "Authorization": f"token {token}"
|
13 | 14 | }
|
14 | 15 |
|
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) |
18 | 20 |
|
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" |
29 | 23 |
|
30 | 24 | # Prepare the badge URL and commit link to update README
|
31 | 25 | badge_url = "https://img.shields.io/badge/GeeksforGeeks-Solution%20of%20the%20Day-blue"
|
32 |
| - badge_link = f"[](https://github.com/{repository})" |
| 26 | + badge_link = f"[](https://github.com/{repository}/blob/main/{month}%202024%20GFG%20SOLUTION/{today_solution_filename})" |
33 | 27 |
|
34 | 28 | # Read the README file and update the sections for commit and badge
|
35 | 29 | with open(readme_path, "r") as readme:
|
36 | 30 | content = readme.read()
|
37 | 31 |
|
38 |
| - # Update commit link |
| 32 | + # Update today's solution link |
39 | 33 | content = re.sub(
|
40 | 34 | 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", |
42 | 36 | content,
|
43 | 37 | flags=re.DOTALL
|
44 | 38 | )
|
|
0 commit comments