Quote:
Originally Posted by capink
I do not understand what you are trying to do with your code, and I do not have the time to debug it. If you can get a working function that returns whatever tags you want, I can help from there.
|
I am very sorry for taking your time, in my original code I was able to get my tags and added an additional label called PROCESSED but with the PRINT function. I don't really know how to do it with Calibre functions. This is the code I have now.
Code:
import re
import ast
import os
with open(r"D:\User\Calibre Portable\Python_tareas\docs_pys\test_dict.txt") as f:
tags_dict = f.read()
def convert_to_text(path_to_epub):
import os, subprocess
from calibre.ptempfile import PersistentTemporaryDirectory
tdir = PersistentTemporaryDirectory('_temp_convert')
output_file = os.path.join(tdir, 'temp.txt')
cmd = 'ebook-convert "{}" "{}"'.format(path_to_epub, output_file)
subprocess.call(cmd, shell='true')
return output_file
def tags_from_epub(path_to_epub):
path_to_txt = convert_to_text(path_to_epub)
temp = []
res = dict()
for line in path_to_txt:
for key,value in tags_dict.items():
if re.search(rf'{value}', line):
if value not in temp:
temp.append(value)
res[key] = value
regex = re.compile(value)
match_array = regex.finditer(line)
match_list = list(match_array)
for m in match_list:
print(key)
print("processed ")
def run(gui, settings, chain):
db = gui.current_db
for book_id in chain.scope().get_book_ids():
fmts = [ fmt.strip() for fmt in db.formats(book_id, index_is_id=True).split(',') ]
if 'EPUB' in fmts:
path_to_epub = db.format_abspath(book_id, 'EPUB', index_is_id=True)
tags_from_epub(path_to_epub)