View Single Post
Old 05-07-2024, 01:19 AM   #988
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,786
Karma: 7029971
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by BrandonGiesing View Post
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)
chaley is offline   Reply With Quote