View Single Post
Old 05-21-2014, 11:12 AM   #9
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,476
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Snow Sciles View Post
chaley, when using strcmp, is it correct to leave the "It" value blank?

Code:
strcmp(
    current_library_name(), 
    'Fanfiction Library', 
    '', 
    sublist(field('#fandom'), 0, 1, ','), 
    field('authors')
)
No. Not-equal strings can compare as less than or greater than, so those two should probably return the same thing.
Quote:
eschwartz, your enthusiasm has convinced me to try program mode. There are two things I'm going try. The first is to create a function that controls the author link in Book Details.

Here is what I've mustered so far

Code:
program:

default = "https://en.wikipedia.org/w/index.php?search={author}";
ao3     = "http://archiveofourown.org/works/search?work_search[creator]={author}";
ffnet   = "https://www.fanfiction.net/search.php?keywords={author}&ready=1&type=writer";

author_lookup = 

        first_matching_cmp(
           field('publisher'),
           'archiveofourown.org',
           ao3,
           'fanfiction.net',
           ffnet,
           default
        );
This works on books that have ao3 or ffnet as publisher. But for those that do not, instead of seeing the default wikipedia link, I get "Could not convert string to float: No such variable publisher".

I don't know what's wrong. I did expect to have to print author_lookup but it seems to work regardless, or perhaps first_match_cmp isn't a good function to use?
The function first_matching_cmp is comparing numbers, not strings. That is why you are getting the error. Also, the function uses a "less than" comparison, which is probably not what you want.

I think you want the switch function. Using that function you would write something like
Code:
author_lookup = 
        switch(
           field('publisher'),
           '^archiveofourown.org$',
           ao3,
           '^fanfiction.net$',
           ffnet,
           default
        );
The regexp anchors are required because "switch", like "contains", uses patterns.
Quote:
The second thing that I'm going to try, is column colouring. I've used the rules method, but Calibre became sluggish. I read this a known consequence of too many rules, so I limited things to only colouring the Title rather than All. Before I try, I want to know if doing it in program mode would prevent that sluggishness?
It will probably have no effect. Rules are converted to GPM templates. The exception is if your hand-built template is significantly less complex than the generated template.

Something to keep in mind for the future: complicated templates can be replaced with hand-coded python functions, which are almost certainly faster, perhaps orders of magnitude. See the "Template functions" preference in the Advanced section. Personally, I wouldn't attempt a template function until I had a GPM template that did what I want. That way I am fighting only one battle, making the python work, instead of two, making it work while determining what it should do.
chaley is offline   Reply With Quote