mirror of
https://github.com/public-apis/public-apis.git
synced 2025-05-15 18:16:50 +02:00
add checks for category minimums and anchor format
This commit is contained in:
parent
f94ca2b8bb
commit
82231641b7
1 changed files with 18 additions and 2 deletions
|
@ -1,10 +1,12 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
import string
|
import string
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
anchor = '###'
|
anchor = '###'
|
||||||
|
min_entries_per_section = 3
|
||||||
auth_keys = ['apiKey', 'OAuth', 'X-Mashape-Key', 'No']
|
auth_keys = ['apiKey', 'OAuth', 'X-Mashape-Key', 'No']
|
||||||
punctuation = ['.', '?', '!']
|
punctuation = ['.', '?', '!']
|
||||||
https_keys = ['Yes', 'No']
|
https_keys = ['Yes', 'No']
|
||||||
|
@ -55,9 +57,23 @@ def check_format(filename):
|
||||||
# END Alphabetical Order
|
# END Alphabetical Order
|
||||||
|
|
||||||
# START Check Entries
|
# START Check Entries
|
||||||
|
num_in_category = min_entries_per_section + 1
|
||||||
|
anchor_re = re.compile('###\s\S+')
|
||||||
for line_num, line in enumerate(lines):
|
for line_num, line in enumerate(lines):
|
||||||
|
# check each section for the minimum number of entries
|
||||||
|
if line.startswith(anchor):
|
||||||
|
if not anchor_re.match(line):
|
||||||
|
add_error(line_num, "section header is not formatted correctly")
|
||||||
|
if num_in_category < min_entries_per_section:
|
||||||
|
add_error(category_line, "{} section does not have the minimum {} entries (only has {})".format(
|
||||||
|
category, min_entries_per_section, num_in_category))
|
||||||
|
category = line.split(' ')[1]
|
||||||
|
category_line = line_num
|
||||||
|
num_in_category = 0
|
||||||
|
continue
|
||||||
if not line.startswith('|') or line.startswith('|---'):
|
if not line.startswith('|') or line.startswith('|---'):
|
||||||
continue
|
continue
|
||||||
|
num_in_category += 1
|
||||||
segments = line.split('|')[1:-1]
|
segments = line.split('|')[1:-1]
|
||||||
# START Global
|
# START Global
|
||||||
for segment in segments:
|
for segment in segments:
|
||||||
|
@ -75,7 +91,7 @@ def check_format(filename):
|
||||||
# first character should be capitalized
|
# first character should be capitalized
|
||||||
char = segments[index_desc][0]
|
char = segments[index_desc][0]
|
||||||
if char.upper() != char:
|
if char.upper() != char:
|
||||||
add_error(line_num, "first char of Description is not capitalized")
|
add_error(line_num, "first character of description is not capitalized")
|
||||||
# last character should not punctuation
|
# last character should not punctuation
|
||||||
char = segments[index_desc][-1]
|
char = segments[index_desc][-1]
|
||||||
if char in punctuation:
|
if char in punctuation:
|
||||||
|
@ -103,7 +119,7 @@ def check_format(filename):
|
||||||
# url should be wrapped in '[Go!]()' Markdown syntax
|
# url should be wrapped in '[Go!]()' Markdown syntax
|
||||||
link = segments[index_link]
|
link = segments[index_link]
|
||||||
if not link.startswith('[Go!](http') or not link.endswith(')'):
|
if not link.startswith('[Go!](http') or not link.endswith(')'):
|
||||||
add_error(line_num, 'link format should be "[Go!](LINK)"')
|
add_error(line_num, 'link syntax should be "[Go!](LINK)"')
|
||||||
# END Link
|
# END Link
|
||||||
# END Check Entries
|
# END Check Entries
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue