awesome-youtubers/linter/rules/content_about.py

62 lines
1.8 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-23 15:15:43 -05:00
class ContentAbout():
2021-02-18 19:15:27 -05:00
"""
2021-02-23 15:15:43 -05:00
Contains methods for the detection of various
rules asigned to the "Content about:" sections.
These methods edit the readme.md file (the awe-
some list) in-place if any of the rules isn't
met.
Attributes:
checker (str): matches the "Content about:" string.
result (str): result of the operation.
2021-02-19 11:04:53 -05:00
"""
2021-02-18 19:15:27 -05:00
2021-02-23 15:15:43 -05:00
checker = "Content about:"
def __init__(self):
self.result = "🟢 No errors found."
def trailing_slash(self) -> str:
"""
Looks for backslash and the end of all the matching
lines ("Content about:" lines).
"""
for line, value in enumerate(content_readme):
if self.checker in value:
last = value[-2]
if last != '\\':
if last == ' ':
content_readme[line] = f"{value[:-1]}\\\n"
else:
content_readme[line] = f"{value[:-1]} \\\n"
2021-02-19 17:50:57 -05:00
with open(file_readme, 'w') as write_readme:
write_readme.writelines(content_readme)
2021-02-23 15:15:43 -05:00
self.result = "🔴 Trailing slash wasn't found.\nFixed."
return self.result
def comma_separated(self) -> str:
"""
Looks through all words in the section to check
if they're separated by a comma and a space
", ".
"""
2021-02-19 17:50:57 -05:00
2021-02-23 15:15:43 -05:00
# for line, value in enumerate(content_readme):
# if self.checker in value:
2021-02-19 11:04:53 -05:00
2021-02-23 15:15:43 -05:00
return self.result
2021-02-06 14:48:34 -05:00
2021-02-11 18:24:13 -05:00
2021-02-23 15:15:43 -05:00
content_about = ContentAbout()
print(content_about.trailing_slash())