forked from benbarth/hacktoberfest-swag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate-alphabetical.py
42 lines (30 loc) · 946 Bytes
/
validate-alphabetical.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
#!/usr/bin/env python
import sys
def main():
if len(sys.argv) != 2:
print("Missing argument: Markdown file path")
sys.exit(1)
isAlphabetical = validateAlphabetical(sys.argv[1])
if not isAlphabetical:
sys.exit(1)
def validateAlphabetical(markdownFilePath):
r = open(markdownFilePath, 'r')
lines = r.readlines()
values = []
tableRow = -1
for line in lines:
if '|' in line:
if tableRow > 0:
columns = line.split('|')
if len(columns) > 1:
firstColumn = columns[1].strip()
values.append(firstColumn)
tableRow += 1
if values != sorted(values, key=str.casefold):
print ("Error: The first column of the table is not alphabetical.")
for value in values:
print(value)
return False
return True
if __name__ == '__main__':
main()