-
Notifications
You must be signed in to change notification settings - Fork 28
/
insert_entry.py
38 lines (28 loc) · 1.25 KB
/
insert_entry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import re
def insert_client_alphabetically(client_name, repo_link, file_path):
with open(file_path, 'r') as file:
lines = file.readlines()
new_entry_line = f"| {client_name} | {repo_link} |\n"
entry_regex = re.compile(r'\| .+ \| .+ \|')
total_clients = 0
inserted = False
for index, line in enumerate(lines):
if entry_regex.match(line):
total_clients += 1
curr_client_name = line.split('|')[1].strip()
if client_name.lower() < curr_client_name.lower() and not inserted:
lines.insert(index, new_entry_line)
inserted = True
total_clients += 1
if not inserted:
lines.append(new_entry_line)
total_clients += 1
header_index = next(i for i, line in enumerate(lines) if line.startswith("# Client Collection List"))
lines[header_index] = f"# Client Collection List - Total Clients: {total_clients}\n"
with open(file_path, 'w') as file:
file.writelines(lines)
if __name__ == "__main__":
client_name = input("Enter the new client's name: ")
repo_link = input("Enter the new client's repository link: ")
file_path = "README.md"
insert_client_alphabetically(client_name, repo_link, file_path)