View Single Post
Old 01-08-2025, 08:12 AM   #19
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: 12,463
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Comfy.n View Post
I thought the template used for titles would run fine for authors, but I couldn't make it work. Here's what I want to automate via Action Chains:

One click executes a search and replace to change 'john smith' to 'John Smith'.

Tried this in bulk metadata dialog:

Spoiler:
python:
def evaluate(book, context):
import re
nt = []
for w in re.split(r'([ _.()])', book.get('author')):
nt.append(w.capitalize())
return ''.join(nt)

@chaley, I wonder if such a feature would be implementable/welcome in the bulk MDE, similar to the title case functionality.

edit: just found how to do this, without a template, in Bulk MDE: it's 'Apply function after replace'
The template didn't work because authors is a multi-valued field (a list). The template must process it author-by-author. Like this:
Code:
python:
def evaluate(book, context):
	import re
	new_auts = []
	for author in book.authors:
		aut = []
		for w in re.split(r'([ _.()])', author):
			aut.append(w.capitalize())
		new_auts.append(''.join(aut))
	return ' & '.join(new_auts)
chaley is offline   Reply With Quote