Quote:
Originally Posted by chaley
Yet another alternate approach would be to write a calibre python script that processes the relationship column to create another tags-like column containing the values you want. This would have great performance and be somewhat easier to maintain, but still suffers from having to do it in python. An example of what this might look like is under the spoiler.
Spoiler:
Code:
def init_cache(library_path):
from calibre.db.backend import DB
from calibre.db.cache import Cache
backend = DB(library_path)
cache = Cache(backend)
cache.init()
return cache
from collections import defaultdict
cache = init_cache(library_path = sys.argv[1])
transformation_dict = {
'Sherlock Holmes': 'Holmes',
'S. Holmes': 'Holmes',
'John Watson': 'Watson',
'J. Watson': 'Watson',
'Sebastian Moran': 'Moran',
'S. Moran': 'Moran',
'Jim Moriarty': 'Moriarty',
'J. Moriarty': 'Moriarty'
}
values_to_write = {}
for id_ in cache.all_book_ids():
relationships = cache.field_for('#mytextmult', id_)
new_relationships = []
if relationships:
for relationship in relationships:
pair = relationship.split('/')
if len(pair) == 2:
left, right = pair
newleft = transformation_dict.get(left, left)
newright = transformation_dict.get(right, right)
new_relationships.append(newleft + '/' + newright)
else:
new_relationships.append(relationship)
values_to_write[id_] = new_relationships
print values_to_write
cache.set_field('#mytextmult', values_to_write)
|
Dealing with templates and regex I learned by now.

Now it seems I have to learn something new... again. I think the last option could be more my solution BUT where do I put something like this? Never have done that before. Now I need a bit more information
Mini