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 12-19-2021, 04:54 AM   #226
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:
		if $rating ==# 0 && $#fanficstatus != '(In-Progress|Abandoned)' && $#vls !='Documentation & Manuals'  then
			'rating.png'
The In-Progress|Abandoned bit failed to work. How do I set "if it does not match this regex"?
The != operator is precisely that: case-sensitive not equals. It doesn't take a regex.

If you want to use a regex then you should use the 'in' operator. Because you want it negated, use
Code:
! ('^(In-Progress|Abandoned)$' in $#fanficstatus)
Alternatively use
Code:
($#fanficstatus != 'Abandoned' && $#fanficstatus != 'In-Progress')
or
Code:
! ($#fanficstatus == 'Abandoned' || $#fanficstatus == 'In-Progress')
To understand the difference between the above two expressions see a description of De Morgan's Law.
Quote:
Also, #vls should be an inlist. How do I set a "is not inlist"?

Use the '!' operator, e.g.,
Code:
! ('^Documentation & Manuals$' inlist $#vls)
The parentheses are there to avoid problems with operator precedence. You want to be sure that the '!' applies to the result of 'inlist' instead of 'Documentation & Manuals'. In fact the precedence of '!' is lower than the comparison operators (executes after them) but using parenthesis to state your intent is always a good idea.

I wonder if you shouldn't sign up to an Intro to Computer Science course.

Last edited by chaley; 12-20-2021 at 10:34 AM. Reason: Change 'not' to the operator !
chaley is offline   Reply With Quote
Old 12-20-2021, 06:39 AM   #227
kevn57
Connoisseur
kevn57 began at the beginning.
 
kevn57's Avatar
 
Posts: 93
Karma: 10
Join Date: Jun 2011
Location: Albany NY
Device: Moonreader+
Could someone please tell me how to get 2 decimal places

program: ($$#minutes / 60)

when I try
program: ($$#minutes / 60){0:5.2f}
or
program: {0:.2f}.format($$#minutes / 60)

I get a template error

Last edited by kevn57; 12-20-2021 at 06:48 AM.
kevn57 is offline   Reply With Quote
Advert
Old 12-20-2021, 06:53 AM   #228
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 kevn57 View Post
Could someone please tell me how to get 2 decimal places

program: ($$#minutes / 60)

when I try
program: ($$#minutes / 60){0:5.2f}
or
program: {0:.2f}.format($$#minutes / 60)

I get a template error
You can't intermix general program mode and single function mode template syntax.

Use the format_number() function. Something like
Code:
program: format_number($$#minutes / 60, '5.2f')
chaley is offline   Reply With Quote
Old 12-20-2021, 07:50 AM   #229
kevn57
Connoisseur
kevn57 began at the beginning.
 
kevn57's Avatar
 
Posts: 93
Karma: 10
Join Date: Jun 2011
Location: Albany NY
Device: Moonreader+
Thanks chaley, I kept trying to mix calibre and python help pages, I never would have come up with that and it works perfectly.
kevn57 is offline   Reply With Quote
Old 12-20-2021, 07:58 AM   #230
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 kevn57 View Post
Thanks chaley, I kept trying to mix calibre and python help pages, I never would have come up with that and it works perfectly.
If you haven't, take a look at The calibre template language and in particular General Program Mode and the template Function reference.
chaley is offline   Reply With Quote
Advert
Old 12-20-2021, 08:19 AM   #231
kevn57
Connoisseur
kevn57 began at the beginning.
 
kevn57's Avatar
 
Posts: 93
Karma: 10
Join Date: Jun 2011
Location: Albany NY
Device: Moonreader+
Thank you again, before I posted I did look at the Function reference that's where I came up with the {0:5.2f} part. In the help details it says " See the template language and Python documentation for more examples." So I started searching for python formatting help. That's where I came up with the {0:.2f}.format.

Looking back at the doc. now it makes a lot more sense.
kevn57 is offline   Reply With Quote
Old 12-20-2021, 09:48 AM   #232
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,012
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Is there any functional difference between

Code:
check_yes_no(field('#bool'), '', '', '1')
and

Code:
check_yes_no(field('#bool'), 0, 0, 1)
ownedbycats is online now   Reply With Quote
Old 12-20-2021, 10:08 AM   #233
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,012
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Also, a question regarding doing math in mixed-use composite columns:

I have a composite column, #chapters, which pulls from integer #chaptercount and provides formatted output. One of those is showing how many chapters of a fanfic I've read (pulled from the Kobo bookmarks column). Another of the outputs is "Not Set" if I haven't set a #chaptercount.

I have an action in one of my action chains that checks the #chapters column to see if there's unread chapter and then changes the #percentread from 100 => 98 if so.

If it matters, #chapters is set to sort by text.

Code:
program:
f = re($#chapters, '(.*)/.*', '\1');
s = re($#chapters, '.*/(.*)', '\1');

	if and(
		$$#fanficcat,
		check_yes_no('#onkobo', '', 1, 1),
		$$#percentread ==#100,
		(s - f) ==# 1
	)

	then '98'
	
	else $$#percentread
	
	fi

This fails with "not set" books. Template tester says could not convert string to float: 'Not Set' Which then breaks the chain when running on books with unset chaptercounts -- I'm guessing from trying to do the math.

I tried adding a $#chapters != 'Not Set', to the checks, but that didn't work. Any idea what I missed?

EDIT: I think I figured it out. I should've set the 'not set' check as a separate check first. Then if it passed make another if with the other checks. Something like this (I probably messed up the indents.)

Code:
program:
f = re($#chapters, '(.*)/.*', '\1');
s = re($#chapters, '.*/(.*)', '\1');

	if 
		$#chapters != 'Not Set'
		then if and(
		$$#fanficcat,
		check_yes_no('#onkobo', '', 1, 1),
		$$#percentread ==#100,
		(s - f) ==# 1
	) 

	then '98'

	
	else $$#percentread
	
	fi 
		fi

Last edited by ownedbycats; 12-20-2021 at 10:19 AM.
ownedbycats is online now   Reply With Quote
Old 12-20-2021, 10:08 AM   #234
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
Is there any functional difference between

Code:
check_yes_no(field('#bool'), '', '', '1')
and

Code:
check_yes_no(field('#bool'), 0, 0, 1)
First, you have the first parameter to check_yes_no() wrong. It is the field name, not the field value. Example:
Code:
check_yes_no('#bool', '', '', '1')
If you use field('...') then almost certainly check_yes_no() will return what is specified for is_undefined. It might return something else if the value of the field is itself a field name. It is possible that this is what you want because you don't know the field name until execution. For example, this would work:
Code:
check_yes_no(strcat('#', 'bool'), '', '', '1')
To answer your question, there is in general no difference between 1 and '1'. The value gets converted back and forth as needed. However, '' and 0 are not the same. The first is the empty string and the second results in the string '0'.

But to make things a bit more confusing the check_yes_no() function checks if the parameter is a 1 (or '1'). Anything else is assumed to be 0. Because of this peculiarity the following three are equivalent:
Code:
check_yes_no('#mybool', 0, 0, 1)
check_yes_no('#mybool', '', '', 1)
check_yes_no('#mybool', 'mybad', 'ohno', '1')
You should not depend on peculiarities like this. Do what the manual says: use the numbers 0 and 1.
chaley is offline   Reply With Quote
Old 12-20-2021, 10:28 AM   #235
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
Also, another Action Chains issue:

I have a composite column, #chapters, which pulls from integer #chaptercount and provides formatted output. One of the outputs is "Not Set" if I haven't set a #chaptercount.

I have an action in one of my chains that checks the #chapters column to see if there's unread chapter and then changes the #percentread from 100 => 98 if so.

If it matters, technically #chapters is set to sort by text.

Code:
program:
f = re($#chapters, '(.*)/.*', '\1');
s = re($#chapters, '.*/(.*)', '\1');

	if and(
		$$#fanficcat,
		check_yes_no('#onkobo', '', 1, 1),
		$$#percentread ==#100,
		(s - f) ==# 1
	)

	then '98'
	
	else $$#percentread
	
	fi

This fails with "not set" books. Template tester says could not convert string to float: 'Not Set' Which then breaks the chain when running on books with unset chaptercounts.

I tried adding a $#chapters != 'Not Set', to the checks, but that didn't work. Any idea what I missed?
As a said before, you could profit from a course in computer science.

What you are seeing is the difference between evaluation of parameters for a function and shortcutting for operators. For a function, all of the parameters are evaluated then passed to the function, in this case 'and()'. Because they are all evaluated the test $#chapters != 'Not Set', doesn't stop evaluation of the other parameters.

However, if using shortcutting then evaluation stops once the result cannot change. For example
Code:
if '' && 2 * 3 then
will not evaluate the expression 2 * 3 because the clause (False && anything) will be False no matter the value of 'anything'.

Using shortcutting we can fix your condition in one of two ways:
Code:
	if $#chapters != 'Not Set' &&
		and(
		$$#fanficcat,
		check_yes_no('#onkobo', '', 1, 1),
		$$#percentread ==#100,
		(s - f) ==# 1
		)
	then ...
or as I would prefer for performance reasons
Code:
	if $#chapters != 'Not Set' &&
		$$#fanficcat &&
		check_yes_no('#onkobo', '', 1, 1) &&
		$$#percentread ==#100 &&
		(s - f) ==# 1
	then ...
Why performance? With shortcutting the evaluation of the conditions stops if a condition is False. With parameters all the conditions are evaluated no matter if one of them is False. Note that this argues that the most common False condition should come earlier in the && list.
chaley is offline   Reply With Quote
Old 12-20-2021, 10:36 AM   #236
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
@ownedbycats: BTW: yet again I led you astray in this reply.

I typed the word 'not' instead of the operator '!'. It worked only because the parentheses turned the 'not' into a function call. The operator has much better performance than the function.

I fixed the post.

Last edited by chaley; 12-20-2021 at 10:49 AM. Reason: Make it clear whom I am talking to.
chaley is offline   Reply With Quote
Old 12-20-2021, 02:07 PM   #237
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
EDIT: I think I figured it out. I should've set the 'not set' check as a separate check first. Then if it passed make another if with the other checks. Something like this (I probably messed up the indents.)

Code:
program:
f = re($#chapters, '(.*)/.*', '\1');
s = re($#chapters, '.*/(.*)', '\1');

	if 
		$#chapters != 'Not Set'
		then if and(
		$$#fanficcat,
		check_yes_no('#onkobo', '', 1, 1),
		$$#percentread ==#100,
		(s - f) ==# 1
	) 

	then '98'

	
	else $$#percentread
	
	fi 
		fi
If using this method, which BTW is a good one, then for performance it would be better to move the s and f calculations into the inner if. Something like this (I didn't try to run/compile it):
Code:
program:

	if 
		$#chapters != 'Not Set'
		then 
			f = re($#chapters, '(.*)/.*', '\1');
			s = re($#chapters, '.*/(.*)', '\1');
			if and(
				$$#fanficcat,
				check_yes_no('#onkobo', '', 1, 1),
				$$#percentread ==#100,
				(s - f) ==# 1
			) 
			then '98'
			else $$#percentread
			fi
# IS SOMETHING SUPPOSED TO GO HERE?
# In the original template this would return $$#percentread
# The new code returns the empty string
		fi
chaley is offline   Reply With Quote
Old 12-20-2021, 03:18 PM   #238
imNOTdwight
Member
imNOTdwight began at the beginning.
 
Posts: 12
Karma: 10
Join Date: Dec 2020
Device: Kobo Libra H2O
Hello.

Is there anyway to "read" the filetype being sent to the device?

I wanted to do a conditional that would place epubs, kepubs and pdfs on different places in my device.

Example:

book.epub -> .books/{authors}-{series:||-}{series_index:||-}{title}

book.kepub -> books/{authors}/{title}

book.pdf -> pdf/{title}

Thanks in advance
imNOTdwight is offline   Reply With Quote
Old 12-20-2021, 05:47 PM   #239
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,012
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
What I do is have a #kobopath column that handles the different preferences. then I plug that into the path itself.

You can either make a composite or use Action Chains to generate it in a standard text column. If you use the latter you'll want to use {#kobopath:re(_,/)} instead of just {kobopath} to keep your slashes working.
ownedbycats is online now   Reply With Quote
Old 12-20-2021, 07:46 PM   #240
imNOTdwight
Member
imNOTdwight began at the beginning.
 
Posts: 12
Karma: 10
Join Date: Dec 2020
Device: Kobo Libra H2O
Quote:
Originally Posted by ownedbycats View Post
What I do is have a #kobopath column that handles the different preferences. then I plug that into the path itself.
I thought about doing that. But it won't work if I want to have two formats of the same book on the device. It's the same “two files one path problem”.

I might just be better of using kepubs exclusively and pdfs where appropriate.
imNOTdwight 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 218 07-11-2025 07:34 PM
[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 05:39 PM.


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