-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
update_list.py
41 lines (31 loc) · 1.48 KB
/
update_list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/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("∕", "/").replace("\", "\\").replace(
"˸", ":").replace("∗", "*").replace("?", "?").replace(
""",
"\"").replace("﹤",
"<").replace("﹥",
">").replace("❘", "|"))
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))