Quote:
Originally Posted by BrandonGiesing
Code isn't working, throws the error:
|
Use this:
Code:
python:
def evaluate(book, context):
field = 'tags'
# Get the previously computed set of acceptable items, if it exists
all_names_over_count = context.globals.get('all_names_over_count')
if all_names_over_count is None:
from calibre.gui2.ui import get_gui
db = get_gui().current_db.new_api
all_names_over_count = set()
counts_by_item = db.get_usage_count_by_id(field)
for item,count in counts_by_item.items():
if count > 5:
all_names_over_count.add(db.get_item_name(field, item))
context.globals['all_names_over_count'] = all_names_over_count
# Check if the current book has any of the acceptable items
item_names_in_book = []
for name in book.get(field):
if name in all_names_over_count:
item_names_in_book.append(name)
return ':@:'.join(item_names_in_book)