Hi all, forgive me if the answer to this is obvious; everything I've learned about coding has been from this forum and from Stack Overflow answers, but this time I can't seem to find an answer.
I use Calibre primarily for fanfics, and as anyone familiar with ao3 knows, there's a lot of variation in the spelling/punctuation/grammar of tags for tags of the same meaning. So, after I've imported the fics to Calibre with the FanFicFare plugin, I use template functions in Action Chains to edit those tags to make them universal, and then move specific ones into my own custom columns (separating freeform tags, characters, ships, etc). (Since many authors have a tendency to put things like ships and characters in with their freeform tags, I find it easier to do the bulk of the editing in Calibre functions with regular expressions rather than in the edits you can do in FanFicFare's ini file at import, and then distribute them to their columns after the fact.)
My question comes with using those Calibre stored template functions. Say I want to remove the last names of characters—I have five different columns that I can make those edits to, and therefore five functions saved, all identical except for the very first line where I call the specific column. How can I make it to where I can change what column to act on when I call the function from Action Chains?
So, an example of the saved function saved as "clipNames_characters":
Code:
python:
def evaluate(book, context):
t0 = context.funcs.field('#characters');
t1 = context.funcs.re(t0,"Search Terms 1", "Replacement 1");
t2 = context.funcs.re(t1,"Search Terms 2", "Replacement 2");
***(etc multiple lines of the rest of the code)***
return t193
Then in Action Chains, I use "Single Field Edit", apply to the "#characters" column, and in the template I put
Code:
program:clipNames_characters();
I use the same method for the "tags" column, and for custom columns I've labeled "#romantic", "#platonic", and "#filtered_tags". But every time I change the code a bit, I have to go in to those saved functions and essentially copy/paste everything beyond that first "t0" line, and I want to figure out a way to where it's just one function where I can change the column affected when I call it within Action Chains. (Not the part where I select what column to apply Single Field Edit to, but the part within the template.)
I hope this all made sense; let me know if you have questions or answers.