File indexing completed on 2024-04-28 04:41:46

0001 #!/usr/bin/env python3
0002 
0003 # SPDX-FileCopyrightText: 2024 Jonah BrĂ¼chert <jbb@kaidan.im>
0004 #
0005 # SPDX-License-Identifier: LGPL-2.0-or-later
0006 
0007 import sys
0008 from bs4 import BeautifulSoup
0009 import subprocess
0010 
0011 table_path = sys.argv[1]
0012 cpp_path   = sys.argv[2]
0013 
0014 table = open(table_path, "r")
0015 soup = BeautifulSoup(table, 'html.parser')
0016 
0017 rows = soup.find_all("tr")
0018 
0019 map = {}
0020 
0021 for row in rows:
0022     data = row.find_all("td")
0023     if len(data) == 8:
0024         map[data[0].get_text().strip()] = data[2].get_text().strip()
0025         map[data[1].get_text().strip()] = data[3].get_text().strip()
0026 
0027     if len(data) == 4:
0028             map[data[0].get_text().strip()] = data[1].get_text().strip()
0029 
0030 
0031 out = open(cpp_path, "w")
0032 out.write("{\n")
0033 for row in map.items():
0034     k = row[0]
0035     v = row[1]
0036     out.write(f"    {{u'{k}', u\"{v}\"}},\n")
0037 
0038 out.write("}")
0039 out.close()