Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify language list in place and add count
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
- Loading branch information
Showing
5 changed files
with
49 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import posixpath | ||
from urllib.parse import quote | ||
import re | ||
|
||
|
||
def regexReplace(string, search, replacement): | ||
return re.compile(search).sub(replacement, string) | ||
|
||
|
||
languageCount = 0 | ||
languagesText = "" | ||
|
||
# List the available languages | ||
for directory in sorted(os.listdir('.')): | ||
if not (directory == '.' or directory == '..' or directory[0] == '.' or os.path.isfile(directory)): | ||
for filename in sorted(os.listdir(directory), key=lambda s: s.lower()): | ||
if os.path.isfile(os.path.join(directory, filename)): | ||
language = os.path.splitext(filename)[0].replace( | ||
'-', ' ').replace('_', ' ').title() | ||
languagesText += f'* [{language}]({posixpath.join(quote(directory), quote(filename))})\n' | ||
languageCount += 1 | ||
|
||
result = f"""<!--Languages start--> | ||
## Languages ({languageCount} total) | ||
{languagesText}<!--Languages end-->""" | ||
|
||
readmeContents = open('README.md', 'r', encoding="utf-8").read() | ||
|
||
open('README.md', 'w', encoding="utf-8").write(regexReplace( | ||
readmeContents, r"<!--Languages start-->(.|\n)*<!--Languages end-->", result)) |