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 01-29-2022, 04:41 AM   #316
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,509
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Code:
if select(ids, 'url') then
	if 
		'(Archive of Our Own|Fanfiction.net)' in $publisher 
		&& '(Completed|Abandoned|Oneshot|Incomplete)' in status
	then "metadata.png"

	elif
		!select(ids, 'ao3')
		&& $publisher == 'Archive of Our Own' 
		&& status == 'In-Progress'
		then 'metadata.png' 
	
	elif 
		!select(ids, 'ffnet')
		&& $publisher == 'FanFiction.net'
		&& status == 'In-Progress'
		then "metadata.png" 
	fi 
fi
Would it be able to combine the two bottom elifs into one? Regex (ao3|ffnet) is one way, but is there a way to keep the id/publisher pair separate from each other?
I think you mean something like this:
Code:
program:
	if 
		'(Archive of Our Own|Fanfiction.net)' in $publisher 
		&& '(Completed|Abandoned|Oneshot|Incomplete)' in status
	then "metadata.png"

	elif	(!select(ids, 'ao3')
		 && $publisher == 'Archive of Our Own' 
		 && status == 'In-Progress' )
	      ||
		(!select(ids, 'ffnet')
		 && $publisher == 'FanFiction.net'
		 && status == 'In-Progress')
	then
		"metadata.png" 
	fi
Quote:
EDIT: Another question:

Attachment 191967

Did I somehow accidentally turn it into last_non_empty?
No. But by using a semicolon instead of a comma you turned the two 'if' statements into a single statement sequence, not two parameters. The value of a statement sequence is the last statement in the sequence, in your case the authors if.

It should look like this:
Code:
program:
	first_non_empty(
		if $title then 'title' fi, <==== comma here
		if $authors then 'authors' fi
	)
chaley is offline   Reply With Quote
Old 01-29-2022, 04:58 AM   #317
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: 11,163
Karma: 77304081
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Quote:
Originally Posted by chaley View Post
I think you mean something like this:
Code:
program:
	if 
		'(Archive of Our Own|Fanfiction.net)' in $publisher 
		&& '(Completed|Abandoned|Oneshot|Incomplete)' in status
	then "metadata.png"

	elif	(!select(ids, 'ao3')
		 && $publisher == 'Archive of Our Own' 
		 && status == 'In-Progress' )
	      ||
		(!select(ids, 'ffnet')
		 && $publisher == 'FanFiction.net'
		 && status == 'In-Progress')
	then
		"metadata.png" 
	fi
Thanks Since both of them use in-progress I was able to reduce it a tiny bit more:
Code:
elif						
	(status == 'In-Progress' &&
	(!select(ids, 'ao3')  && $publisher == 'Archive of Our Own') 						
	||
	(!select(ids, 'ffnet') && $publisher == 'FanFiction.net')	
	)
then "metadata.png"
ownedbycats is offline   Reply With Quote
Old 01-29-2022, 05:11 AM   #318
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,509
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Thanks Since both of them use in-progress I was able to reduce it a tiny bit more:
Code:
elif						
	(status == 'In-Progress' &&
	(!select(ids, 'ao3')  && $publisher == 'Archive of Our Own') 						
	||
	(!select(ids, 'ffnet') && $publisher == 'FanFiction.net')	
	)
then "metadata.png"
You should pay attention to operator precedence and the implied parentheses. The && operator has higher precedence than the || operator, so your statement will evaluate like this:
Code:
program:
if
		(	status == 'In-Progress' &&
			(!select(ids, 'ao3')  && $publisher == 'Archive of Our Own') 						
		) 
	||
		(
			(!select(ids, 'ffnet') && $publisher == 'FanFiction.net')	
		)
then "metadata.png"
fi
That isn't what you want because the status == isn't done for the 'ffnet' branch. Instead you want this:
Code:
program:
if	status == 'In-Progress' &&
	(
			(!select(ids, 'ao3')  && $publisher == 'Archive of Our Own')

		||
			(!select(ids, 'ffnet') && $publisher == 'FanFiction.net')	
	)
then "metadata.png"
fi
By putting the second two checks in parentheses you ensure that the status == check is done for both of them.

My advice: don't depend on operator precedence unless you really know what you are doing. Instead use parentheses to specify the order of evaluation.

EDIT: I forgot to mention: factoring conditions in ifs is a very good thing for performance and readability. It makes the flow clearer and takes maximum advantage of condition short circuiting. Good that you noticed it.

Last edited by chaley; 01-29-2022 at 10:45 AM.
chaley is offline   Reply With Quote
Old 01-30-2022, 07:06 AM   #319
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: 11,163
Karma: 77304081
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
The downside of nesting ifs is that it's very easy to misplace fis. I've gotten into the habit of adding ## Start/End [something] check comments just so I remember what they belong to.
ownedbycats is offline   Reply With Quote
Old 01-30-2022, 07:39 AM   #320
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,509
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
The downside of nesting ifs is that it's very easy to misplace fis. I've gotten into the habit of adding ## Start/End [something] check comments just so I remember what they belong to.
That is one reason that consistent indenting is so important. If done correctly the if and fi will be at the same indent.

One trick you can use to match a fi with its if. Put a left parenthesis in front of the if. The editor will complain about a syntax error. Now put a right parenthesis after the fi that you think matches (but before any semicolon). If the error goes away then they indeed match. If there is still an error then the if and fi don't match.
chaley is offline   Reply With Quote
Old 01-30-2022, 11:01 PM   #321
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: 11,163
Karma: 77304081
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
That will be useful to know

Also, something like this

Code:
if 
	variable == 'foo' 
	&& anothervariable
	&& thirdvariable != 'bar' 
then
	'foobar'
makes it easier to comment out specific checks to see how things change.
ownedbycats is offline   Reply With Quote
Old 01-31-2022, 07:52 PM   #322
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: 11,163
Karma: 77304081
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Does if $#columname== '' work for all undefined columntypes? (excluding the default columns 'title' and 'author')

Last edited by ownedbycats; 01-31-2022 at 07:55 PM.
ownedbycats is offline   Reply With Quote
Old 02-01-2022, 03:55 AM   #323
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,509
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Does if $#columname== '' work for all undefined columntypes? (excluding the default columns 'title' and 'author')
Yes, undefined is rendered as the empty string for all column types. The columns title and author aren't special in this sense, but they are never undefined.

Note that !$#mumble is equivalent to $#mumble=='' but faster.
chaley is offline   Reply With Quote
Old 02-01-2022, 11:13 PM   #324
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: 11,163
Karma: 77304081
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
EDIT: It was a regex error.

Last edited by ownedbycats; 02-02-2022 at 12:01 AM.
ownedbycats is offline   Reply With Quote
Old 02-03-2022, 03:56 AM   #325
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: 11,163
Karma: 77304081
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Not quite a template question, but did I make a mistake on this saved search? I'm getting VL recursion errors:

Code:
NOT formats:(paperbook|overdrive) OR NOT formats:#=1
EDIT: Changing to formats:"~(overdrive|paperbook)" worked. Not exactly sure why.

Last edited by ownedbycats; 02-03-2022 at 09:22 PM.
ownedbycats is offline   Reply With Quote
Old 02-03-2022, 12:35 PM   #326
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: 11,163
Karma: 77304081
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Code:
program: 

   strcat(
		icons_readstatus(),
		icons_fanfic(),
		icons_devicestatus(),
		icons_formats(),
	)
How do I add a colon to this so that the icon strings don't run together? icons_readstatus()':' made an error and 'icons_readstatus():' returned literally that.
ownedbycats is offline   Reply With Quote
Old 02-03-2022, 01:08 PM   #327
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,509
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Code:
program: 

   strcat(
		icons_readstatus(),
		icons_fanfic(),
		icons_devicestatus(),
		icons_formats()
	)
How do I add a colon to this so that the icon strings don't run together? icons_readstatus()':' made an error and 'icons_readstatus():' returned literally that.
Code:
program: 

   strcat(
		icons_readstatus(), ':', 
		icons_fanfic(), ':',
		icons_devicestatus(), ':',
		icons_formats(),
	)
chaley is offline   Reply With Quote
Old 02-04-2022, 08:13 AM   #328
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: 11,163
Karma: 77304081
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Silly question:

I have this rule in emblems:

Code:
program: 

	first_non_empty(
		icons_cleanup_metadata(),
		icons_cleanup_missingids(),
		icons_cleanup_fanfic(),
		icons_marked(),
		if 'Cleanup' in virtual_libraries() then 'polish.png' fi
	)
Line 7 results in a duplicate pin icon, like this:

Click image for larger version

Name:	2022-02-04 09_10_03-Window.png
Views:	619
Size:	82.8 KB
ID:	192107

So I tried replacing with if is_marked() then '' fi and... wait, that's an empty:

Click image for larger version

Name:	2022-02-04 09_11_59-Window.png
Views:	605
Size:	81.5 KB
ID:	192108

Invis.png doesn't really work quite as expected either:

Click image for larger version

Name:	2022-02-04 09_12_49-Window.png
Views:	608
Size:	82.4 KB
ID:	192109

Is there a better option than first_non_empty? For now, I'm using if is_marked() then 'nope' fi as that won't render anything.

Last edited by ownedbycats; 02-04-2022 at 08:20 AM.
ownedbycats is offline   Reply With Quote
Old 02-04-2022, 08:46 AM   #329
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,509
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Silly question:

I have this rule in emblems:

Code:
program: 

	first_non_empty(
		icons_cleanup_metadata(),
		icons_cleanup_missingids(),
		icons_cleanup_fanfic(),
		icons_marked(),
		if 'Cleanup' in virtual_libraries() then 'polish.png' fi
	)
[...]
Is there a better option than first_non_empty? For now, I'm using if is_marked() then 'nope' fi as that won't render anything.
You can use a series of ifs like this:
Code:
program: 
	if 	v = icons_cleanup_metadata() then v
	elif	v = icons_cleanup_missingids() then v
	elif	v = icons_cleanup_fanfic() then v
	elif	v = icons_marked() then v
	elif   'Cleanup' in virtual_libraries() then 'polish.png'
	fi
It stops at the first condition that is true, returning whatever v is even if it is empty.

With your change the icons_marked line would become
Code:
	elif	is_marked() then ''
The condition is true so it returns the empty string.

The two 'tricks' are:
  • The value of an if statement is the value of a then or else block. That is why it has the value of the first evaluated then block.
  • Use the embedded assignment so you don't need to call the function (stored template) twice or can return whatever you want as you do in the last elif.
chaley is offline   Reply With Quote
Old 02-04-2022, 08:53 AM   #330
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,509
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
BTW: you can also do it using a series of ifs with return statements as long as you don't do any processing after the last one.
Code:
program: 
	if v = icons_cleanup_metadata() then return v fi;
	if v = icons_cleanup_missingids() then return v fi;
	if v = icons_cleanup_fanfic() then return v fi;
	if is_marked() then return '' fi;
	if 'Cleanup' in virtual_libraries() then return 'polish.png' fi
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Library Management: various questions not worth their own thread ownedbycats Library Management 234 08-22-2025 05:42 AM
[Metadata Source Plugin] Questions regarding parse select, docs and ref templates Boilerplate4U Development 13 07-07-2020 02:35 AM
Questions on Kobo [Interfered with another thread topic] spdavies Kobo Reader 8 10-12-2014 11:37 AM
[OLD Thread] Some questions before buying the fire. darthreader13 Kindle Fire 7 05-10-2013 09:19 PM
Thread management questions meme Feedback 6 01-31-2011 05:07 PM


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


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