View Single Post
Old 03-21-2024, 11:09 AM   #21
moldy
Enthusiast
moldy began at the beginning.
 
Posts: 43
Karma: 10
Join Date: Oct 2015
Device: Kindle
I can't get this to work.The function considers that it has made just 1 replacement but actually it hasn't. Please view image at:



My find code is:
Code:
<body[^>]*>\K(.+)</body>
And my function is:
Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    
    from calibre.utils.config import JSONConfig
    m = match[0]


    if number == 1:
        fname = 'beatstones.json'
        data['equiv'] = JSONConfig(fname)
        if not data['equiv']:
            print(f'Problem loading {fname}, no treatment will be done')
    
    return data['equiv'].get(m, m)

            
    import regex
    m = match.group() 
    for key in equiv:
        m = regex.sub(rf'\b{key}\b', equiv[key], m)
    return m
There are no errors reported. As far as I can see there are no problems from the json file and I can extract the keys from it. It must be a problem with the function but, with my limited knowledge, I can't find it.
moldy is offline   Reply With Quote