You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB

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