Set all lines the same function

This commit is contained in:
Jose De Freitas 2021-02-19 17:50:57 -05:00
parent 256d6e72a0
commit d0d687325c
3 changed files with 71 additions and 28 deletions

View File

@ -21,16 +21,18 @@ def 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'
if value[-2] != '\\':
if value[-2] == ' ':
content_readme[line] = value[:-1] + '\\' + '\n'
with open(file_readme, 'w') as write_readme:
write_readme.writelines(content_readme)
result = "Found errors. Fixed them."
# Check for comma separated words
else:
content_readme[line] = value[:-1] + ' \\' + '\n'
with open(file_readme, 'w') as write_readme:
write_readme.writelines(content_readme)
result = "Trailing slash wasn't found.\nFixed."
return result

View File

@ -1,21 +1,42 @@
import pathlib
here = pathlib.Path(__file__).parent
file_readme = here / './../readme.md'
file_readme = here / '../../test.md'
with open(file_readme, 'r') as read_readme:
content_readme = read_readme.readlines()
def featured_playlists():
featured_playlists_errors_nums = []
featured_playlists_line = 'Featured playlists:'
featured_playlists_dlen = 124
"""
Looks for trailing slashes and words separated by commas at
every "Featured playlists:" section found in the readme.md file
(this is, the list itself).
for j, i in enumerate(content_readme):
if featured_playlists_line in i:
if len(i) < featured_playlists_dlen and i[-2] != '\\':
featured_playlists_errors_nums.append(j)
return featured_playlists_errors_nums
result (str): return value of the function.
checker (str): detector of the line corresponding the file.
length (int): length of the corresponding line.
"""
result = 'No errors found.'
checker = 'Featured playlists:'
length = 124
for line, value in enumerate(content_readme):
if checker in value:
# Check for trailing slash
if len(value) < length and value[-2] != '\\':
if value[-2] == ' ':
content_readme[line] = value[:-1] + '\\' + '\n'
with open(file_readme, 'w') as write_readme:
write_readme.writelines(content_readme)
else:
content_readme[line] = value[:-1] + ' \\' + '\n'
with open(file_readme, 'w') as write_readme:
write_readme.writelines(content_readme)
result = "Trailing slash wasn't found.\nFixed."
return result
featured_playlists_errors_nums = featured_playlists()
print(featured_playlists())

View File

@ -1,20 +1,40 @@
import pathlib
here = pathlib.Path(__file__).parent
file_readme = here / './../readme.md'
file_readme = here / '../../test.md'
with open(file_readme, 'r') as read_readme:
content_readme = read_readme.readlines()
def youtubers_names():
youtubers_name_errors_nums = []
youtuber_count_char = '[**'
"""
Looks for trailing slashes and words separated by commas at
every YouTuber's name line found in the readme.md file
(this is, the list itself).
for j, i in enumerate(content_readme):
if youtuber_count_char in i:
if i[-2] != '\\':
youtubers_name_errors_nums.append(j)
return youtubers_name_errors_nums
result (str): return value of the function.
checker (str): detector of the line corresponding the file.
"""
result = 'No errors found.'
checker = '[**'
for line, value in enumerate(content_readme):
if checker in value:
# Check for trailing slash
if value[-2] != '\\':
if value[-2] == ' ':
content_readme[line] = value[:-1] + '\\' + '\n'
with open(file_readme, 'w') as write_readme:
write_readme.writelines(content_readme)
else:
content_readme[line] = value[:-1] + ' \\' + '\n'
with open(file_readme, 'w') as write_readme:
write_readme.writelines(content_readme)
result = "Trailing slash wasn't found.\nFixed."
return result
youtubers_name_errors_nums = youtubers_names()
print(youtubers_names())