diff --git a/web/convert_table.py b/web/convert_table.py new file mode 100644 index 0000000..01e8c69 --- /dev/null +++ b/web/convert_table.py @@ -0,0 +1,27 @@ +def convert_table(lines): + def from_ascii(): + out = [] + first, header, third, *body, last = lines + first = first.translate(str.maketrans({'-': '━', '+': '┯'})) + out.append(f'┏{first[1:-1]}┓') + header = header.translate(str.maketrans({'|': '│'})) + out.append(f'┃{header[1:-1]}┃') + third = third.translate(str.maketrans({'-': '─', '+': '┼'})) + out.append(f'┠{third[1:-1]}┨') + for line in body: + line = line.translate(str.maketrans({'|': '│'})) + line = line.replace('yes', ' ✓ ') + out.append(f'┃{line[1:-1]}┃') + last = last.translate(str.maketrans({'-': '━', '+': '┷'})) + out.append(f'┗{last[1:-1]}┛') + return '\n'.join(out) + def from_unicode(): + out = [] + for line in lines: + line = line.translate(str.maketrans('┏┓┗┛┠┼┨┯┷━─┃│', '+++++++++--||')) + line = line.replace(' ✓ ', 'yes') + out.append(line) + return '\n'.join(out) + if lines[0][0] == '+': + return from_ascii() + return from_unicode() \ No newline at end of file diff --git a/web/create_index.py b/web/create_index.py new file mode 100755 index 0000000..cd64401 --- /dev/null +++ b/web/create_index.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +# +# Usage: .py +# + +from collections import namedtuple +from dataclasses import make_dataclass +from enum import Enum +import re +import sys +from bs4 import BeautifulSoup +from collections import defaultdict + + +def main(): + html = read_file('index.html') + doc = BeautifulSoup(''.join(html), 'html.parser') + hhh = defaultdict(lambda: defaultdict(list)) + for i in range(2, 5): + for h in doc.find_all(f'h{i}'): + an_id = h.attrs['id'] + text = h.text.lstrip('#') + first_letter = text[0] + hhh[first_letter][text].append(an_id) + print_hhh(hhh) + + +def print_hhh(hhh): + letters = hhh.keys() + for letter in sorted(letters): + hh = hhh[letter] + print(f'### {letter}') + commands = hh.keys() + for command in sorted(commands): + links = hh[command] + lll = ', '.join(f'[1](#{l})' for l in links) + print(f'**{command} {lll}** ') + print() + + +### +## UTIL +# + +def read_file(filename): + with open(filename, encoding='utf-8') as file: + return file.readlines() + + +if __name__ == '__main__': + main() \ No newline at end of file