refactoring
This commit is contained in:
@@ -112,7 +112,7 @@ def update_readme():
|
||||
|
||||
# assemble output
|
||||
update = ['- **[{}](games/{}/_toc.md)** ({})\n'.format(*entry) for entry in info]
|
||||
update = "".join(update)
|
||||
update = "{} entries".format(sum(n)) + "".join(update)
|
||||
|
||||
# insert new text in the middle
|
||||
text = start + "[comment]: # (start of autogenerated content, do not edit)\n" + update + "\n[comment]: # (end of autogenerated content)" + end
|
||||
@@ -220,7 +220,7 @@ def fix_notation():
|
||||
"""
|
||||
Changes notation, quite special. Only run when needed.
|
||||
"""
|
||||
regex = re.compile(r"- Wikipedia:(.*)")
|
||||
regex = re.compile(r"- License details:(.*)")
|
||||
|
||||
# get category paths
|
||||
category_paths = get_category_paths()
|
||||
@@ -244,7 +244,7 @@ def fix_notation():
|
||||
match = match[0]
|
||||
|
||||
# patch content
|
||||
content[line] = "- Media:{}\n".format(match)
|
||||
content[line] = "- Code license details:{}\n".format(match)
|
||||
|
||||
# write it line by line
|
||||
with open(entry_path, "w") as f:
|
||||
@@ -312,7 +312,13 @@ def parse_entry(content):
|
||||
if matches:
|
||||
languages = matches[0].split(',')
|
||||
languages = [x.strip() for x in languages]
|
||||
info['Language'] = languages
|
||||
info['language'] = languages
|
||||
|
||||
# license
|
||||
regex = re.compile(r"- License: (.*)")
|
||||
matches = regex.findall(content)
|
||||
if matches:
|
||||
info['license'] = matches[0]
|
||||
|
||||
return info
|
||||
|
||||
@@ -349,25 +355,45 @@ def generate_statistics():
|
||||
|
||||
# Language
|
||||
statistics += '## Languages\n\n'
|
||||
number_no_language = sum(1 for x in infos if 'Language' not in x)
|
||||
number_no_language = sum(1 for x in infos if 'language' not in x)
|
||||
if number_no_language > 0:
|
||||
statistics += '{} ({:.1f}%) have no language tag\n\n'.format(number_no_language, number_no_language / number_entries * 100)
|
||||
entries_no_language = [x['file'][:-3] for x in infos if 'Language' not in x] # [:-3] to cut off the .md
|
||||
statistics += 'Without language tag: {} ({:.1f}%)\n\n'.format(number_no_language, number_no_language / number_entries * 100)
|
||||
entries_no_language = [x['file'][:-3] for x in infos if 'language' not in x] # [:-3] to cut off the .md
|
||||
entries_no_language.sort()
|
||||
statistics += ', '.join(entries_no_language) + '\n\n'
|
||||
|
||||
# get all languages together
|
||||
languages = []
|
||||
for info in infos:
|
||||
if 'Language' in info:
|
||||
languages.extend(info['Language'])
|
||||
if 'language' in info:
|
||||
languages.extend(info['language'])
|
||||
|
||||
unique_languages = set(languages)
|
||||
unique_languages = [(l, languages.count(l) / len(languages)) for l in unique_languages]
|
||||
unique_languages.sort(key=lambda x: -x[1])
|
||||
unique_languages = ['{} ({:.1f}%)'.format(x[0], x[1]*100) for x in unique_languages]
|
||||
statistics += '\n'.join(unique_languages) + '\n\n'
|
||||
unique_languages = ['- {} ({:.1f}%)\n'.format(x[0], x[1]*100) for x in unique_languages]
|
||||
statistics += 'Used languages:\n' + ''.join(unique_languages) + '\n'
|
||||
|
||||
# Licenses
|
||||
statistics += '## Licenses\n\n'
|
||||
number_no_license = sum(1 for x in infos if 'license' not in x)
|
||||
if number_no_license > 0:
|
||||
statistics += 'Without license tag: {} ({:.1f}%)\n\n'.format(number_no_license, number_no_license / number_entries * 100)
|
||||
entries_no_license = [x['file'][:-3] for x in infos if 'license' not in x] # [:-3] to cut off the .md
|
||||
entries_no_license.sort()
|
||||
statistics += ', '.join(entries_no_license) + '\n\n'
|
||||
|
||||
# get all licenses together
|
||||
licenses = []
|
||||
for info in infos:
|
||||
if 'license' in info:
|
||||
licenses.append(info['license'])
|
||||
|
||||
unique_licenses = set(licenses)
|
||||
unique_licenses = [(l, licenses.count(l) / len(licenses)) for l in unique_licenses]
|
||||
unique_licenses.sort(key=lambda x: -x[1])
|
||||
unique_licenses = ['- {} ({:.1f}%)\n'.format(x[0], x[1]*100) for x in unique_licenses]
|
||||
statistics += 'Used licenses:\n' + ''.join(unique_licenses) + '\n'
|
||||
|
||||
with open(statistics_path, 'w') as f:
|
||||
f.write(statistics)
|
||||
@@ -396,7 +422,7 @@ if __name__ == "__main__":
|
||||
#check_validity_external_links()
|
||||
|
||||
# special, only run when needed
|
||||
#fix_notation()
|
||||
# fix_notation()
|
||||
|
||||
# regular replacements
|
||||
#regular_replacements()
|
||||
Reference in New Issue
Block a user