Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old Today, 06:13 PM   #1
ToastedTabby
Lurker
ToastedTabby began at the beginning.
 
Posts: 1
Karma: 10
Join Date: Jun 2024
Device: none
Using RegEx to find and replace in varying columns

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.
ToastedTabby is offline   Reply With Quote
Reply

Tags
custom col, regex, stored templates, template functions


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
New to regex find and replace! ksimpson1986 Sigil 2 11-06-2016 11:29 AM
regex cannot find to replace eschwartz Editor 11 02-03-2014 11:00 PM
Regex find and replace SanatyrZeo Sigil 5 10-29-2012 07:03 AM
RegEx find and replace iblesq Sigil 1 01-10-2011 09:26 PM
REGEX find and replace help please potestus Sigil 13 09-18-2010 04:14 PM


All times are GMT -4. The time now is 09:43 PM.


MobileRead.com is a privately owned, operated and funded community.