more autogenerated info on category pages

This commit is contained in:
Trilarion
2017-12-07 15:00:58 +01:00
parent ac7e911b08
commit 0edab10b12
8 changed files with 178 additions and 120 deletions

View File

@@ -13,6 +13,40 @@ def read_first_line_from_file(file):
line = f.readline()
return line
def read_interesting_info_from_file(file):
"""
Parses a file for some interesting fields and concatenates the content
"""
with open(file, 'r') as f:
text = f.read()
output = [None, None, None]
# language
regex = re.compile(r"- Language\(s\): (.*)")
matches = regex.findall(text)
if matches:
output[0] = matches[0]
# license
regex = re.compile(r"- License: (.*)")
matches = regex.findall(text)
if matches:
output[1] = matches[0]
# state
regex = re.compile(r"- State: (.*)")
matches = regex.findall(text)
if matches:
output[2] = matches[0]
output = [x for x in output if x] # eliminate empty entries
output = " " + ", ".join(output)
return output
def update_readme():
"""
Recounts entries in subcategories and writes them to the readme
@@ -59,7 +93,7 @@ def update_readme():
update = "".join(update)
# insert new text in the middle
text = start + update + end
text = start + "[comment]: # (start of autogenerated content, do not edit)\n" + update + "\n[comment]: # (end of autogenerated content)" + end
# write to readme
with open(readme_path, 'w') as f:
@@ -88,18 +122,21 @@ def update_category_tocs():
# get titles (discarding first two ("# ") and last ("\n") characters)
titles = [read_first_line_from_file(path)[2:-1] for path in paths]
# get more interesting info
more = [read_interesting_info_from_file(path) for path in paths]
# combine name and file name
info = zip(titles, files)
info = zip(titles, files, more)
# sort according to title
info.sort(key=lambda x:x[0])
# assemble output
update = ['- [{}]({})\n'.format(*entry) for entry in info]
update = ['- [{}]({}){}\n'.format(*entry) for entry in info]
update = "".join(update)
# combine toc header
text = toc_header + '\n' + update
text = toc_header + '\n' + "[comment]: # (start of autogenerated content, do not edit)\n" + update + "\n[comment]: # (end of autogenerated content)"
# write to toc file
with open(toc_file, 'w') as f: