05-24-2019, 05:47 PM | #1 |
Enthusiast
Posts: 33
Karma: 1032
Join Date: Nov 2016
Device: Kobo Aura Edition 2, Lenovo Android 10
|
Adding logic to send to device template
Hi all!
I've been using a template to send books to my Android tablet, Chaley helped me refine it in a previous thread back in 2016. I want to add more refinement to the template to further sort books on my device. Here's the current template: Code:
program: ta = test(field('series'), strcat(field('series'),'/',field('#serind'),' - ',field('#firstauth'),' - ',field('title')), strcat(field('#firstauth'),' - ',field('title'))); str_in_list(field('tags'), ',', 'Fiction', strcat('eBooks/Fiction/', ta), strcat('eBooks/Non-Fiction/', ta)))) If fiction If Sci-Fi OR Fantasy put in sci-fi fantasy folder else put in thriller folder put in non-fiction folder I understand that this will be a nesting of str_in_list commands, but my question is regarding the OR in the second if statement, how do I do OR in Calibre? Code:
str_in_list(field('tags'), ',', 'Sci-Fi', {OR} 'Fantasy' |
05-24-2019, 08:37 PM | #2 |
null operator (he/him)
Posts: 20,625
Karma: 26960534
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
|
Advert | |
|
05-25-2019, 08:26 AM | #3 |
Grand Sorcerer
Posts: 11,761
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
A variant of this template will do what you want, using the ability of regular expressions to do an "or". Fix "ta" (I don't have all your columns). Also, I am not sure what column contains the Sci-Fi and Fantasy values. I assumed it was "tags".
Code:
program: ta = 'aaa'; t = field('tags'); str_in_list(t, ',', 'Fiction', in_list(t, ',', '^(Sci-Fi|Fantasy)$', strcat('eBooks/sci-fi or fantasy/', ta), strcat('eBooks/thriller/', ta)), strcat('eBooks/Non-Fiction/', ta)) |
05-26-2019, 03:59 AM | #4 |
Enthusiast
Posts: 33
Karma: 1032
Join Date: Nov 2016
Device: Kobo Aura Edition 2, Lenovo Android 10
|
Thanks BetterRed and chaley. I took a look at the boolean function link, would this also work?
Code:
str_in_list(field('tags'), ',', or('Sci-Fi', 'Fantasy') .... |
05-26-2019, 05:35 AM | #5 | ||
Grand Sorcerer
Posts: 11,761
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Quote:
NB: You could use the "str_in_list" function instead of in_list to avoid using regex. Something like this: Code:
str_in_list(t, ',', 'Sci-Fi,Fantasy', strcat('eBooks/sci-fi or fantasy/', ta), strcat('eBooks/thriller/', ta)) |
||
Advert | |
|
Tags |
code, send to device, template |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Send to Device Template not working | dkperez | Library Management | 3 | 12-01-2016 08:36 PM |
Send to device - Template help | Snow Sciles | Library Management | 12 | 05-26-2014 05:16 PM |
Issue with Send to Device template | BookJunkieLI | Library Management | 5 | 02-14-2014 01:16 AM |
Template Help - Send to device | Snow Sciles | Library Management | 4 | 10-08-2013 07:54 AM |
Send to device template | rockeh | Calibre | 6 | 08-17-2010 05:28 PM |