Skip to content

Commit 7ccc0bb

Browse files
committed
Added helper scripts
1 parent 9532bf0 commit 7ccc0bb

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

web/convert_table.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
def convert_table(lines):
2+
def from_ascii():
3+
out = []
4+
first, header, third, *body, last = lines
5+
first = first.translate(str.maketrans({'-': '━', '+': '┯'}))
6+
out.append(f'┏{first[1:-1]}┓')
7+
header = header.translate(str.maketrans({'|': '│'}))
8+
out.append(f'┃{header[1:-1]}┃')
9+
third = third.translate(str.maketrans({'-': '─', '+': '┼'}))
10+
out.append(f'┠{third[1:-1]}┨')
11+
for line in body:
12+
line = line.translate(str.maketrans({'|': '│'}))
13+
line = line.replace('yes', ' ✓ ')
14+
out.append(f'┃{line[1:-1]}┃')
15+
last = last.translate(str.maketrans({'-': '━', '+': '┷'}))
16+
out.append(f'┗{last[1:-1]}┛')
17+
return '\n'.join(out)
18+
def from_unicode():
19+
out = []
20+
for line in lines:
21+
line = line.translate(str.maketrans('┏┓┗┛┠┼┨┯┷━─┃│', '+++++++++--||'))
22+
line = line.replace(' ✓ ', 'yes')
23+
out.append(line)
24+
return '\n'.join(out)
25+
if lines[0][0] == '+':
26+
return from_ascii()
27+
return from_unicode()

web/create_index.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Usage: .py
4+
#
5+
6+
from collections import namedtuple
7+
from dataclasses import make_dataclass
8+
from enum import Enum
9+
import re
10+
import sys
11+
from bs4 import BeautifulSoup
12+
from collections import defaultdict
13+
14+
15+
def main():
16+
html = read_file('index.html')
17+
doc = BeautifulSoup(''.join(html), 'html.parser')
18+
hhh = defaultdict(lambda: defaultdict(list))
19+
for i in range(2, 5):
20+
for h in doc.find_all(f'h{i}'):
21+
an_id = h.attrs['id']
22+
text = h.text.lstrip('#')
23+
first_letter = text[0]
24+
hhh[first_letter][text].append(an_id)
25+
print_hhh(hhh)
26+
27+
28+
def print_hhh(hhh):
29+
letters = hhh.keys()
30+
for letter in sorted(letters):
31+
hh = hhh[letter]
32+
print(f'### {letter}')
33+
commands = hh.keys()
34+
for command in sorted(commands):
35+
links = hh[command]
36+
lll = ', '.join(f'[1](#{l})' for l in links)
37+
print(f'**{command} {lll}** ')
38+
print()
39+
40+
41+
###
42+
## UTIL
43+
#
44+
45+
def read_file(filename):
46+
with open(filename, encoding='utf-8') as file:
47+
return file.readlines()
48+
49+
50+
if __name__ == '__main__':
51+
main()

0 commit comments

Comments
 (0)