awesome-youtubers/linter/rules/content_about.py

39 lines
1.2 KiB
Python
Raw Normal View History

2021-02-06 15:26:52 -05:00
import pathlib
here = pathlib.Path(__file__).parent
2021-02-18 19:15:27 -05:00
file_readme = here / '../../test.md'
2021-02-06 14:48:34 -05:00
with open(file_readme, 'r') as read_readme:
content_readme = read_readme.readlines()
2021-02-11 18:24:13 -05:00
2021-02-06 14:48:34 -05:00
def content_about():
2021-02-18 19:15:27 -05:00
"""
Looks for trailing slashes and words separated by commas at
every "Content about:" section found in the readme.md file
(this is, the list itself).
2021-02-11 18:24:13 -05:00
2021-02-19 11:04:53 -05:00
result (str): return value of the function.
checker (str): detector of the line corresponding the file.
"""
2021-02-18 19:15:27 -05:00
2021-02-19 11:04:53 -05:00
result = 'No errors found.'
checker = 'Content about:'
for line, value in enumerate(content_readme):
if checker in value:
# words = i[len(checker):-2].split(', ')
# Check for trailing slash
if value[-1] != '\\':
last = value[-2:-1]
replaced = last.replace(' ', '\\', 1)
content_readme[line] = value[:-2] + ' ' + replaced + '\n'
2021-02-18 19:15:27 -05:00
with open(file_readme, 'w') as write_readme:
write_readme.writelines(content_readme)
2021-02-19 11:04:53 -05:00
result = "Found errors. Fixed them."
# Check for comma separated words
return result
2021-02-06 14:48:34 -05:00
2021-02-11 18:24:13 -05:00
2021-02-18 19:15:27 -05:00
print(content_about())