-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfuction_manage.py
43 lines (36 loc) · 1.15 KB
/
fuction_manage.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
39
40
41
42
43
"""
code for managing the CONTRIBUTOR.md file.
how this works?
- Remove trailing whitespaces before '####'
- Replace every heading with '####'
- Sort the list of contributors
Running the script -
python3 manage.py
PS: DO NOT USE PYTHON 2
"""
import re
def format_contributor(contrib):
return contrib
# Remove trailing whitespaces
# Make the file ready for sorting
with open('Contributors.md', 'r+') as file:
new_file_data = []
for line in file.readlines():
line = re.sub('^#{1,3} ', '#### ', line)
if(line.startswith(' ##')):
new_file_data.append(line.lstrip())
else:
new_file_data.append(line)
file.seek(0)
file.truncate()
file.writelines(new_file_data)
# Sorts the list of contributors and saves to file
# The real thing happens here.
with open('Contributors.md', 'r+') as file:
contributors = [contributor.strip() for contributor in file.read().split('####')
if contributor]
contributors = [format_contributor(contrib) for contrib in contributors]
contributors = sorted(contributors)
file.seek(0)
file.truncate()
file.writelines(contributors)