awesome-youtubers/linter/rules/content_about.py

64 lines
1.8 KiB
Python
Raw Normal View History

2021-02-06 20:26:52 +00:00
import pathlib
here = pathlib.Path(__file__).parent
2021-02-19 00:15:27 +00:00
file_readme = here / '../../test.md'
2021-02-06 19:48:34 +00:00
with open(file_readme, 'r') as read_readme:
2021-02-24 17:19:43 +00:00
content = read_readme.readlines()
2021-02-06 19:48:34 +00:00
2021-02-11 23:24:13 +00:00
2021-02-23 20:15:43 +00:00
class ContentAbout():
2021-02-19 00:15:27 +00:00
"""
2021-02-23 20:15:43 +00: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 16:04:53 +00:00
"""
2021-02-19 00:15:27 +00:00
2021-02-23 20:15:43 +00:00
checker = "Content about:"
def __init__(self):
2021-02-24 17:19:43 +00:00
self.result = "🟢 0: perfect."
2021-02-23 20:15:43 +00:00
def trailing_slash(self) -> str:
"""
Looks for backslash and the end of all the matching
lines ("Content about:" lines).
"""
2021-02-24 17:19:43 +00:00
for line, value in enumerate(content):
2021-02-23 20:15:43 +00:00
if self.checker in value:
last = value[-2]
2021-02-24 17:19:43 +00:00
if last != "\\":
if last == " ":
content[line] = f"{value[:-1]}\\\n"
2021-02-23 20:15:43 +00:00
else:
2021-02-24 17:19:43 +00:00
content[line] = f"{value[:-1]} \\\n"
2021-02-19 22:50:57 +00:00
with open(file_readme, 'w') as write_readme:
2021-02-24 17:19:43 +00:00
write_readme.writelines(content)
2021-02-26 15:06:16 +00:00
self.result = f"🔴 {line}: backslash.\nFixed."
2021-02-23 20:15:43 +00:00
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 22:50:57 +00:00
2021-02-24 17:19:43 +00:00
# for line, value in enumerate(content):
2021-02-23 20:15:43 +00:00
# if self.checker in value:
2021-02-19 16:04:53 +00:00
2021-02-23 20:15:43 +00:00
return self.result
2021-02-06 19:48:34 +00:00
2021-02-11 23:24:13 +00:00
2021-02-23 20:15:43 +00:00
content_about = ContentAbout()
print(content_about.trailing_slash())