"""Extract definition from existing Kindle dictionaries (For example https://akishop.com.vn/tong-hop-tu-dien-cho-kindle-nd49491.html)
Steps
1. If necessary, use DeDRM Calibre plugin (https://github.com/apprenticeharper/DeDRM_tools/) to remove DRM
2. Use KindleUnpack -r to extract raw data from .prc/.mobi file
3. Run following code to extract and cleanup definitions to a tab-seperated file format
4. Now the output can be run through PyGlossary to convert to many dictionary formats
"""
import re
from email.quoprimime import header_decode
from html import unescape
from bs4 import BeautifulSoup
def striphtml(data):
p = re.compile(r"<.*?>")
return p.sub("", data)
folder = r"./ext-dict/"
FILE_DATA = {
"SPDict-Irregular-Verbs.html": {
"encoding": "utf-8",
"pattern": r"(.+?)
@
-- > (.+?)
",
"remove": r"<[(/i|b|u)\s]*>",
"replace": [],
"skips": 0,
},
"Wikipedia/mobi7/Wikipedia.rawml": {
"encoding": "utf-8",
"pattern": r"