View Single Post
Old 06-04-2025, 06:14 AM   #842
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,449
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Code:
program:	

subjects = $#subjects;
admintags = $#admintags;
existing_colls = $#kobocoll;

	new_colls = strcat(	
		if $#booktype=='Fanfiction' then 'Fanfiction,' fi,
		if '^Cozy Mystery$' inlist subjects then 'Cozy Mysteries,' fi,
		if '^Horses$' inlist subjects then 'Horses,' fi,
		if '(Juvenile|Young Adult)' inlist subjects then 'Juvenile & Young Adults,' fi,
		if '^(Fantasy|Paranormal|Science Fiction)$' inlist subjects && !'Star Trek' inlist subjects then 'Fantasy & Sci-Fi,' fi,
		if '^Star Trek$' inlist subjects then 'Star Trek,' fi,
		if 'Omnibus' in admintags then 'Omnibuses' fi,
	);
Line 12, can be done without the extra inlist?
Yes, it can be done but it is complicated and probably slower. It would be some combination of list_intersection and list_count. It could be done as a python template used as a function, something like
Code:
check_inlist_field(field, values required, values_not_allowed)
but I don't see a pressing need here.

You should use "inlist_field '#subjects'" instead of "inlist subjects".

I also suggest you use parentheses on line 12 to avoid any possibility of operator precidence being what you don't want. Example:
Code:
if ('^(Fantasy|Paranormal|Science Fiction)$' inlist_field '#subjects') && (!('Star Trek' inlist_field '#subjects')) then 'Fantasy & Sci-Fi,' fi,

Last edited by chaley; 06-04-2025 at 06:16 AM.
chaley is offline   Reply With Quote