Register Guidelines E-Books Today's Posts Search

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
Custom User Title
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: 10,926
Karma: 74801041
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly 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 offline   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: 24,905
Karma: 47303824
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
Advert
Old 04-11-2021, 07:07 AM   #3
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,195
Karma: 1995558
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
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,415
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
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
Custom User Title
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: 10,926
Karma: 74801041
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Thanks. I will save these
ownedbycats is offline   Reply With Quote
Advert
Old 05-04-2021, 05:40 PM   #6
ownedbycats
Custom User Title
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: 10,926
Karma: 74801041
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly 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 offline   Reply With Quote
Old 05-04-2021, 05:59 PM   #7
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,415
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
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
Custom User Title
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: 10,926
Karma: 74801041
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly 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 offline   Reply With Quote
Old 05-04-2021, 06:13 PM   #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,415
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
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
Custom User Title
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: 10,926
Karma: 74801041
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly 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 offline   Reply With Quote
Old 05-04-2021, 06:39 PM   #11
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,415
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
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
Custom User Title
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: 10,926
Karma: 74801041
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly 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 offline   Reply With Quote
Old 05-04-2021, 06:58 PM   #13
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,415
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
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
Custom User Title
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: 10,926
Karma: 74801041
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I'm not even sure how that semicolon got there. thank you
ownedbycats is offline   Reply With Quote
Old 05-04-2021, 07:12 PM   #15
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,415
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
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


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom list template Laval Related Tools 6 10-11-2022 09:13 AM
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
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 01:29 AM.


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