|
9 | 9 | token = sys.argv[2]
|
10 | 10 | readme_path = sys.argv[3]
|
11 | 11 |
|
12 |
| - headers = { |
13 |
| - "Authorization": f"token {token}" |
14 |
| - } |
15 |
| - |
16 | 12 | # Get the current date
|
17 | 13 | today = datetime.today()
|
18 | 14 | day_of_month = today.strftime("%d") # Get current day of the month (e.g., 06)
|
19 | 15 | month = today.strftime("%b") # Get current month (e.g., Nov)
|
20 | 16 |
|
21 |
| - # Prepare the solution filename for today (e.g., 06(Nov) Root to leaf paths sum.md) |
22 |
| - today_solution_filename = f"{day_of_month}({month}) Root to leaf paths sum.md" |
23 |
| - |
24 |
| - # Make a request to GitHub to list files in the directory |
25 |
| - dir_url = f"https://api.github.com/repos/{repository}/contents/{month}%202024%20GFG%20SOLUTION" |
26 |
| - response = requests.get(dir_url, headers=headers) |
27 |
| - |
28 |
| - if not response.ok: |
29 |
| - print(f"Failed to fetch files: {response.status_code} {response.text}") |
30 |
| - sys.exit(1) |
31 |
| - |
32 |
| - files = response.json() |
| 17 | + # Prepare the solution filename for today (e.g., 06(Nov)Root to leaf paths sum.md) |
| 18 | + today_solution_filename = f"{day_of_month}({month}){today.strftime('%A')}.md" |
33 | 19 |
|
34 |
| - # Check if the directory exists or if there are any issues |
35 |
| - if isinstance(files, dict) and 'message' in files and files['message'] == 'Not Found': |
36 |
| - print(f"Directory not found: {dir_url}") |
37 |
| - sys.exit(1) |
| 20 | + # Prepare the commit URL for today (we don't need to change this as it will be dynamically picked from the latest commit) |
| 21 | + # solution_url = f"https://github.com/{repository}/blob/main/{month}%202024%20GFG%20SOLUTION/{today_solution_filename}" |
38 | 22 |
|
39 |
| - # Now, we try to find the solution file for today |
40 |
| - today_file = None |
41 |
| - for file in files: |
42 |
| - if file['name'].startswith(f"{day_of_month}({month})"): |
43 |
| - today_file = file['name'] |
44 |
| - break |
45 |
| - |
46 |
| - if not today_file: |
47 |
| - print(f"Solution file for {today_solution_filename} not found.") |
48 |
| - sys.exit(1) |
49 |
| - |
50 |
| - # Prepare the badge URL with the correct link to today's solution |
51 |
| - solution_url = f"https://github.com/{repository}/blob/main/{month}%202024%20GFG%20SOLUTION/{today_file}" |
| 23 | + # Prepare the badge URL and commit link to update README |
52 | 24 | badge_url = "https://img.shields.io/badge/GeeksforGeeks-Solution%20of%20the%20Day-blue"
|
53 |
| - badge_link = f"[]({solution_url})" |
| 25 | + badge_link = f"[]({solution_url})" # This makes the badge link to the solution for today |
54 | 26 |
|
55 |
| - # Read the README file and update the sections for the badge |
| 27 | + # Read the README file and update the sections for commit and badge |
56 | 28 | with open(readme_path, "r") as readme:
|
57 | 29 | content = readme.read()
|
58 | 30 |
|
59 |
| - # Update the badge with the dynamic link to today's solution |
| 31 | + # Update today's solution link (for the commit) |
| 32 | + # content = re.sub( |
| 33 | + # r"(?<=<!--START_SECTION:latest-commit-->).*?(?=<!--END_SECTION:latest-commit-->)", |
| 34 | + # f"\n{solution_url}\n", |
| 35 | + # content, |
| 36 | + # flags=re.DOTALL |
| 37 | + # ) |
| 38 | + |
| 39 | + # Update badge link |
60 | 40 | content = re.sub(
|
61 | 41 | r"(?<=<!--START_SECTION:potd-badge-->).*?(?=<!--END_SECTION:potd-badge-->)",
|
62 | 42 | f"\n{badge_link}\n",
|
|
0 commit comments