Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Devices

Notices

Reply
 
Thread Tools Search this Thread
Old 05-24-2019, 05:47 PM   #1
wishingstar
Enthusiast
wishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheese
 
Posts: 33
Karma: 1032
Join Date: Nov 2016
Device: Kobo Aura Edition 2, Lenovo Android 10
Question 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))))
So, the way I understand this code, str_in_list creates an if-else condition, if true the book goes to the fiction folder, else it goes to non-fiction. Now what if I want to separate thrillers from sci-fi/fantasy? Basically what I want is:

If fiction
If Sci-Fi OR Fantasy
put in sci-fi fantasy folder
else
put in thriller folder
else
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'
Thanks!
wishingstar is offline   Reply With Quote
Old 05-24-2019, 08:37 PM   #2
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 20,457
Karma: 26645808
Join Date: Mar 2012
Location: Sydney Australia
Device: none
See Boolean functions ==>> Function classification

BR
BetterRed is offline   Reply With Quote
Advert
Old 05-25-2019, 08:26 AM   #3
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: 11,703
Karma: 6658935
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))
chaley is offline   Reply With Quote
Old 05-26-2019, 03:59 AM   #4
wishingstar
Enthusiast
wishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheese
 
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') ....
I think your solution, chaley, may be more robust using RegEx(?)
wishingstar is offline   Reply With Quote
Old 05-26-2019, 05:35 AM   #5
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: 11,703
Karma: 6658935
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by wishingstar View Post
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') ....
No, that doesn't work. The or function does not compare strings. You would need to use a string compare operator inside the "or", which makes the function not appropriate in this situation.
Quote:
I think your solution, chaley, may be more robust using RegEx(?)
I am not sure about "robust" but it does the job.

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))
chaley is offline   Reply With Quote
Advert
Reply

Tags
code, send to device, template

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

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


All times are GMT -4. The time now is 02:06 PM.


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