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

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

Notices

Reply
 
Thread Tools Search this Thread
Old 04-11-2021, 12:14 AM   #1
ownedbycats
Wizard
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 2,523
Karma: 10851074
Join Date: Oct 2018
Device: Kobo Aura HD
Template: Matching an entire list

I want one of the clauses of a gpm template to return true iif the only available format is epub. I tested with this:

Code:
program:
	f = $formats;

	if 
		list_contains(f, ',', '^epub$', '1', '') 
	then 'foobar' 
	fi
However, it returns 'foobar' for every book that has epub, even if there's other formats.

What should I do?

EDIT: Also, there are other times I might want to match the entire list contents. I am not sure how to do that though.

Last edited by ownedbycats; 04-11-2021 at 12:32 AM.
ownedbycats is online now   Reply With Quote
Old 04-11-2021, 01:24 AM   #2
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 21,573
Karma: 37261886
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
My first thought is to count the items in the list:

Code:
program:
	f = $formats;
	if 
		(count(f, ',') == 1) && (list_contains(f, ',', '^epub$', '1', '') )
	then 'foobar' 
	fi
But, you can just do:

Code:
program:
	f = $formats;
	if 
		contains(f, '^epub$', '1', '')
	then 'foobar' 
	fi
davidfor is offline   Reply With Quote
Old 04-11-2021, 07:07 AM   #3
capink
Evangelist
capink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipedia
 
Posts: 476
Karma: 47410
Join Date: Aug 2015
Device: Kindle
If you want to extend it so that it is able to test multiple formats also:

Code:
program:
    mandatory_formats = 'epub,mobi';
    if list_equals($formats, ',', mandatory_formats, ',', 1, '') then
        'foobar'
    fi
You can also modify this to be a stored template and use the arguments function so that you are able to pass the mandatory formats to the stored template.
capink is offline   Reply With Quote
Old 04-11-2021, 11:08 AM   #4
chaley
Grumpy old git
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.
 
chaley's Avatar
 
Posts: 9,783
Karma: 3174298
Join Date: Jan 2010
Location: UK
Device: Reader
This template solves the original problem, to test if a book has epub as its only format:
Code:
program:
	if $formats == 'epub' then
		'foobar'
	fi
This works because a list of 1 item has no separating commas.
chaley is offline   Reply With Quote
Old 04-11-2021, 04:48 PM   #5
ownedbycats
Wizard
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 2,523
Karma: 10851074
Join Date: Oct 2018
Device: Kobo Aura HD
Thanks. I will save these
ownedbycats is online now   Reply With Quote
Old 05-04-2021, 05:40 PM   #6
ownedbycats
Wizard
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 2,523
Karma: 10851074
Join Date: Oct 2018
Device: Kobo Aura HD
Related to this: I am trying to remove "Crossover" from fanfics that technically aren't crossovers:

Code:
program:
	f = $#fanficcat;
	if 
		contains(
			f, '^Crossover, Mass Effect Trilogy, Mass Effect: Andromeda$', '1', ''
		)
	then 
		'Mass Effect Trilogy, Mass Effect: Andromeda' 
	elif
		contains(
			f, '^Crossover, Half-Life, Portal$', '1', ''
		)	
		then 'Half-Life, Portal' 
	else
		$#fanficcat;
	fi
However, this fails if the tags aren't in that exact order. Since it appears sorted in book details it's hard to tell. Is there a better way to do this?

Last edited by ownedbycats; 05-04-2021 at 05:51 PM.
ownedbycats is online now   Reply With Quote
Old 05-04-2021, 05:59 PM   #7
chaley
Grumpy old git
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.
 
chaley's Avatar
 
Posts: 9,783
Karma: 3174298
Join Date: Jan 2010
Location: UK
Device: Reader
Quote:
Originally Posted by ownedbycats View Post
Related to this: I am trying to remove "Crossover" from fanfics that technically aren't crossovers:

Code:
program:
	f = $#fanficcat;
	if 
		contains(
			f, '^Crossover, Mass Effect Trilogy, Mass Effect: Andromeda$', '1', ''
		)
	then 
		'Mass Effect Trilogy, Mass Effect: Andromeda' 
	elif
		contains(
			f, '^Crossover, Half-Life, Portal$', '1', ''
		)	
		then 'Half-Life, Portal' 
	else
		$#fanficcat;
	fi
However, this fails on two fronts:

1. In template tester, it only works if the tags are in that exact order. Since it appears sorted in book details it's hard to tell.
2. Putting this in Action Chains' single-field edit on a book that tested fine just results in the column becoming empty.

Any idea how to do this?
The function list_difference() removes items, but it isn't clear what you want to do. Are you asking to remove 'Crossover' if #fanficcat contains some other items, and possibly only those items? What exactly are the rules?

EDIT: writing down the rules can help with formulating the correct expressions. If you run into situations where the answer is "It depends" then you aren't done.
chaley is offline   Reply With Quote
Old 05-04-2021, 06:03 PM   #8
ownedbycats
Wizard
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 2,523
Karma: 10851074
Join Date: Oct 2018
Device: Kobo Aura HD
The blanking out issue I fixed; it was a template error that I fixed in the post before testing in the chain itself.

If the only three items on the list are Crossover, Mass Effect Trilogy, Mass Effect: Andromeda then I want to remove Crossover.

If it's Crossover, foobar, Mass Effect Trilogy, Mass Effect: Andromeda then leave Crossover in.
ownedbycats is online now   Reply With Quote
Old 05-04-2021, 06:13 PM   #9
chaley
Grumpy old git
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.
 
chaley's Avatar
 
Posts: 9,783
Karma: 3174298
Join Date: Jan 2010
Location: UK
Device: Reader
Quote:
Originally Posted by ownedbycats View Post
The blanking out issue I fixed; it was a template error that I fixed in the post before testing in the chain itself.

If the only three items on the list are Crossover, Mass Effect Trilogy, Mass Effect: Andromeda then I want to remove Crossover.

If it's Crossover, foobar, Mass Effect Trilogy, Mass Effect: Andromeda then leave Crossover in.
This is an incredibly specific task that I wonder if it is best done with search/replace. That said, this template or something close to it should do the job
Code:
program:
	f = $#fanficcat;
	if list_count(f, ',') ==# 3 &&
		'^Crossover$' inlist f &&
		'^Mass Effect Trilogy$' inlist f &&
		'^Mass Effect: Andromeda$' inlist f then
			f = 'Mass Effect Trilogy, Mass Effect: Andromeda'
	fi;
	f
chaley is offline   Reply With Quote
Old 05-04-2021, 06:30 PM   #10
ownedbycats
Wizard
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 2,523
Karma: 10851074
Join Date: Oct 2018
Device: Kobo Aura HD
it is pretty specific... the other alternative I thought of is that if I could sort the list before, it would definitely match Crossover, Mass Effect Trilogy, Mass Effect: Andromeda and I could use my original template. Or just checking all nine variations...
ownedbycats is online now   Reply With Quote
Old 05-04-2021, 06:39 PM   #11
chaley
Grumpy old git
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.
 
chaley's Avatar
 
Posts: 9,783
Karma: 3174298
Join Date: Jan 2010
Location: UK
Device: Reader
Quote:
Originally Posted by ownedbycats View Post
it is pretty specific... the other alternative I thought of is that if I could sort the list before, it would definitely match Crossover, Mass Effect Trilogy, Mass Effect: Andromeda and I could use my original template. Or just checking all nine variations...
You should be able to use list_sort() to do it this way. EDIT: But you need to be careful about the spacing. I think that the list will be separated by "comma space", but I can't guarantee that.

Last edited by chaley; 05-04-2021 at 06:42 PM.
chaley is offline   Reply With Quote
Old 05-04-2021, 06:53 PM   #12
ownedbycats
Wizard
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 2,523
Karma: 10851074
Join Date: Oct 2018
Device: Kobo Aura HD
Code:
program:
	f = list_sort($#fanficcat,0,',');

	if 
		contains(
			f, '^Crossover, Mass Effect Trilogy, Mass Effect: Andromeda$', '1', ''
		)
	then 
		'Mass Effect Trilogy, Mass Effect: Andromeda' 
	elif
		contains(
			f, '^Crossover, Half-Life, Portal$', '1', ''
		)	
		then 'Half-Life, Portal' 
	else
		$#fanficcat;
	fi
This gave me a EXCEPTION: Formatter: Expected an expression, found 'fi' near Unknown on line 17.
ownedbycats is online now   Reply With Quote
Old 05-04-2021, 06:58 PM   #13
chaley
Grumpy old git
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.
 
chaley's Avatar
 
Posts: 9,783
Karma: 3174298
Join Date: Jan 2010
Location: UK
Device: Reader
Remove the semicolon on line 16
Code:
$#fanficcat;
A semicolon is a statement separator, not a statement terminator. That means that if a semicolon is found then it must be followed by another expression.

The exception is a semicolon at the end of the program. That is accepted because a) it can be detected and b) so many people put one there that I got tired of the questions.
chaley is offline   Reply With Quote
Old 05-04-2021, 06:59 PM   #14
ownedbycats
Wizard
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 2,523
Karma: 10851074
Join Date: Oct 2018
Device: Kobo Aura HD
I'm not even sure how that semicolon got there. thank you
ownedbycats is online now   Reply With Quote
Old 05-04-2021, 07:12 PM   #15
chaley
Grumpy old git
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.
 
chaley's Avatar
 
Posts: 9,783
Karma: 3174298
Join Date: Jan 2010
Location: UK
Device: Reader
Quote:
Originally Posted by ownedbycats View Post
I'm not even sure how that semicolon got there. thank you
This isn't intended to be criticism ...

When I was first studying computing back in 1971 we had to submit "card decks", a pile of punched computer cards, to run. If *anything* was wrong it cost us hours, so we learned to carefully check the cards for spelling, logic, and syntactic errors before submitting them. Once submitted we would go to the local all-night pizza or donut shop to wait, only to come back to see the error message "You have too many errors. You must be stoned" (yes, this was a real message) and to do it all again.

Today the time penalty for not checking for errors is near zero, so people don't bother. The process is "hack at it until it seems to work." The downside: people have less understanding of the basic details.

On the other hand, today people are using very complex "APIs" (Application Programming Interfaces) that do an incredible amount of work for you. Problem: these APIs aren't sufficiently documented so the only way to determine what they do is to try using them, over and over until one is confident that the behavior is understood. But of course the behavior isn't understood because the edge conditions aren't tested. Sigh...
chaley is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Template: Converting a search & replace into a template ownedbycats Library Management 11 03-26-2021 04:32 AM
Template: Strcat matching ownedbycats Library Management 7 03-20-2021 10:15 PM
Custom list template Laval Related Tools 2 09-27-2017 06:37 PM
Create a template to only list one author. PMGeuze Calibre 2 12-04-2013 02:53 PM


All times are GMT -4. The time now is 04:34 PM.


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