updating update.py

This commit is contained in:
TristanAncelet 2021-09-04 23:11:17 -05:00
parent c35eeadd88
commit 7631164249

View File

@ -1,20 +1,21 @@
import os
import re
article_finder = re.compile(r'- \[\S+\]\((\S+)\)')
def articles_in_readme(readme_path):
article_finder = re.compile(r'- \[\S+\]\((\S+)].md\)')
with open(readme_path, 'r', encoding="UTF-8") as file:
contents = article_finder.findall(file.read())
return article_finder.findall(file.read())
file.close()
return contents
def is_markdown_file(filename):
matcher = re.compile(f'\S+\.md')
matcher = re.compile(r'\S+\.md')
return True if matcher.match(filename) else False
def make_readme_article_name(filename):
word_finder = re.compile(r"_?([A-Z][a-z]+")
return ' '.join(word_finder.findall(filename))
def articles_in_directory(directory):
files = list()
@ -23,12 +24,21 @@ def articles_in_directory(directory):
files.append(file)
def update_readme_contents(directory):
def readme_matches_directory_contents(directory):
if articles_in_readme(os.path.join(directory, 'README.md')) == os.listdir()
return True if (articles_in_readme(os.path.join(directory, 'README.md')) == os.listdir(directory)) else False
def update_readme_contents(directory):
readme_path = os.path.join(directory,"README.md")
files_difference = list(set(articles_in_directory(directory))-set(articles_in_readme(readme_path)))
if len(files_difference) == 0:
logging.debug("update_readme_contents : {} : there were no differences between directory and file".format(readme_path))
else:
with open(readme_path, 'a') as file:
for item in files_difference:
file.write(f"- [{make_readme_article_name(item)}]({item})")
for directory in os.listdir():