Browse Source

Added helper scripts

pull/46/head
Jure Šorn 5 years ago
parent
commit
7ccc0bb14d
2 changed files with 78 additions and 0 deletions
  1. 27
      web/convert_table.py
  2. 51
      web/create_index.py

27
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()

51
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()
Loading…
Cancel
Save