Format output

This commit is contained in:
Jose De Freitas 2021-02-27 19:53:56 -05:00
parent 91e7f28ac1
commit f2b67d98b8
4 changed files with 102 additions and 162 deletions

View File

@ -1,13 +1,33 @@
# from rules.content_about import content_about # Last "as" keyword is in the form ab_cd, where "a" and
# "b" are the first letters of the two words of the module
# and "c" and "d" are the first letters of the two words
# of the function of the module.
from rules.content_about import trailing_slash as ca_ts
from rules.featured_playlists import trailing_slash as fp_ts
from rules.youtubers_names import trailing_slash as yn_ts
def main(): def main() -> None:
""" """
Main function. Used specifically to call print results Main function. Used specifically to call print results
by calling functions into rules/. by calling functions into rules/.
Functions:
content_about: trailing_slash, comma_separated
featured_playlists: trailing_slash, closed_backsticks
youtubers_names: trailing_slash, youtube_link
""" """
pass # "youtubers_names"
print("YouTubers names:")
print(yn_ts())
# "content_about"
print("Content about:")
print(ca_ts())
# "featured_playlists"
print("Featured playlists:")
print(fp_ts())
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -5,59 +5,32 @@ file_readme = here / '../../test.md'
with open(file_readme, 'r') as read_readme: with open(file_readme, 'r') as read_readme:
content = read_readme.readlines() content = read_readme.readlines()
CHECKER = "Content about:"
class ContentAbout():
def trailing_slash() -> str:
""" """
Contains methods for the detection of various Looks for backslash and the end of all the matching
rules asigned to the "Content about:" sections. lines ("Content about:" lines).
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.
""" """
checker = "Content about:" result = ["🟢 0: perfect."]
def __init__(self): for line, value in enumerate(content):
self.result = "🟢 0: perfect." if CHECKER in value:
last = value[-2]
if last != "\\":
if last == " ":
content[line] = f"{value[:-1]}\\\n"
else:
content[line] = f"{value[:-1]} \\\n"
def trailing_slash(self) -> str: with open(file_readme, 'w') as write_readme:
""" write_readme.writelines(content)
Looks for backslash and the end of all the matching
lines ("Content about:" lines).
"""
for line, value in enumerate(content): result.append(f"🔴 {line}: backslash. Fixed.")
if self.checker in value:
last = value[-2]
if last != "\\":
if last == " ":
content[line] = f"{value[:-1]}\\\n"
else:
content[line] = f"{value[:-1]} \\\n"
with open(file_readme, 'w') as write_readme: if len(result) > 1:
write_readme.writelines(content) return '\n'.join(result[1:])
else:
self.result = f"🔴 {line}: backslash.\nFixed." return ''.join(result)
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
", ".
"""
# for line, value in enumerate(content):
# if self.checker in value:
return self.result
content_about = ContentAbout()
print(content_about.trailing_slash())

View File

@ -5,76 +5,52 @@ file_readme = here / '../../test.md'
with open(file_readme, 'r') as read_readme: with open(file_readme, 'r') as read_readme:
content = read_readme.readlines() content = read_readme.readlines()
CHECKER = "Featured playlists:"
LENGTH = 124
class FeaturedPlaylists():
def trailing_slash() -> str:
""" """
Contains methods for the detection of various Looks for backslash and the end of all the matching
rules asigned to the "Featured playlists:" sections. lines ("Featured playlists:" lines) and a line
These methods edit the readme.md file (the awe- break tag "<br>" at the next line.
some list) in-place if any of the rules isn't
met.
Attributes:
checker (str): matches the "Featured playlists:" string.
length (int): minimum length of the line to break line.
result (str): result of the operation.
""" """
checker = "Featured playlists:" result = ["🟢 0: perfect."]
length = 124
def __init__(self): for line, value in enumerate(content):
self.result = "🟢 0: perfect." if CHECKER in value:
last = value[-2]
if len(value) < LENGTH:
if last != "\\" and "<br>" not in content[line+1]:
if last == " ":
content[line] = f"{value[:-1]}\\\n<br>\n"
else:
content[line] = f"{value[:-1]} \\\n<br>\n"
def trailing_slash(self): with open(file_readme, 'w') as write_readme:
""" write_readme.writelines(content)
Looks for backslash and the end of all the matching
lines ("Featured playlists:" lines) and a line
break tag "<br>" at the next line.
"""
for line, value in enumerate(content): result.append(f"🔴 {line}: backslash | line break. Fixed.")
if self.checker in value: elif last != "\\" and "<br>" in content[line+1]:
last = value[-2] if last == " ":
if len(value) < self.length: content[line] = f"{value[:-1]}\\\n"
if last != "\\" and "<br>" not in content[line+1]: else:
if last == " ": content[line] = f"{value[:-1]} \\\n"
content[line] = f"{value[:-1]}\\\n<br>\n"
else:
content[line] = f"{value[:-1]} \\\n<br>\n"
with open(file_readme, 'w') as write_readme: with open(file_readme, 'w') as write_readme:
write_readme.writelines(content) write_readme.writelines(content)
self.result = f"🔴 {line}: backslash | line break.\nFixed." result.append(f"🔴 {line}: backslash. Fixed.")
elif last != "\\" and "<br>" in content[line+1]: elif last == "\\" and "<br>" not in content[line+1]:
if last == " ": content[line+1] = "<br>\n\n"
content[line] = f"{value[:-1]}\\\n"
else:
content[line] = f"{value[:-1]} \\\n"
with open(file_readme, 'w') as write_readme: with open(file_readme, 'w') as write_readme:
write_readme.writelines(content) write_readme.writelines(content)
self.result = f"🔴 {line}: backslash.\nFixed." result.append(f"🔴 {line}: line break. Fixed.")
elif last == "\\" and "<br>" not in content[line+1]:
content[line+1] = "<br>\n\n"
with open(file_readme, 'w') as write_readme: if len(result) > 1:
write_readme.writelines(content) return '\n'.join(result[1:])
else:
self.result = f"🔴 {line}: line break.\nFixed." return ''.join(result)
return self.result
def closed_backsticks(self):
"""
Looks that all backsticks of every word are co-
rrectly opened and subsequent closed.
"""
return self.result
featured_playlists = FeaturedPlaylists()
print(featured_playlists.trailing_slash())

View File

@ -5,61 +5,32 @@ file_readme = here / '../../test.md'
with open(file_readme, 'r') as read_readme: with open(file_readme, 'r') as read_readme:
content = read_readme.readlines() content = read_readme.readlines()
CHECKER = "[**"
class YoutubersNames():
def trailing_slash() -> str:
""" """
Contains methods for the detection of various Looks for backslash and the end of all the matching
rules asigned to the YouTubers names lines. lines (YouTubers names lines).
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 YouTuber names
"[**" string.
result (str): result of the operation.
""" """
checker = "[**" result = ["🟢 0: perfect."]
def __init__(self): for line, value in enumerate(content):
self.result = "🟢 0: perfect." if CHECKER in value:
last = value[-2]
if last != "\\":
if last == " ":
content[line] = f"{value[:-1]}\\\n"
else:
content[line] = f"{value[:-1]} \\\n"
def trailing_slash(self): with open(file_readme, 'w') as write_readme:
""" write_readme.writelines(content)
Looks for backslash and the end of all the matching
lines (YouTubers names lines).
"""
for line, value in enumerate(content): result.append(f"🔴 {line}: backslash. Fixed.")
if self.checker in value:
last = value[-2]
if last != "\\":
if last == " ":
content[line] = f"{value[:-1]}\\\n"
else:
content[line] = f"{value[:-1]} \\\n"
with open(file_readme, 'w') as write_readme: if len(result) > 1:
write_readme.writelines(content) return '\n'.join(result[1:])
else:
self.result = f"🔴 {line}: backslash.\nFixed." return ''.join(result)
return self.result
def youtube_link(self):
"""
Checks whether the link typed is from youtube.com.
"""
link = "youtube.com"
for line, value in enumerate(content):
if self.checker in value:
if link not in value:
self.result = f"🔴 {line}: YouTube link."
return self.result
youtubers_names = YoutubersNames()
print(youtubers_names.trailing_slash())