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-07-2022, 04:21 AM   #271
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,199
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
You can pass variables to stored templates using the arguments function (read the documentation for more info)
  • You should first modify your stored templates to look like this
    Code:
    program:
        arguments(date);
        now = format_date(today(), 'yyyy-MM-dd');
    
        if days_between(date, now) <= '1' then '#aaaaa'
        elif days_between(date, now) <= '3' then '#bbbbb'
        elif days_between(date, now) <= '7' then '#ccccc' 
        fi
  • Now you can call the stored template with the date argument as follows:
    Code:
    program:
        colours_daysbetween($#fanficupdated)
capink is offline   Reply With Quote
Old 01-07-2022, 01:37 PM   #272
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,037
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
That works! Can more than one argument be set per template? e.g. swapping "#aaaa" for "colourA" and then setting that in the external template.

Also, I found out the issue I was having with days_between -- I put the arguments in the wrong order and getting negative numbers which were all less than 1. I think I made this mistake before.

Last edited by ownedbycats; 01-07-2022 at 01:40 PM.
ownedbycats is online now   Reply With Quote
Advert
Old 01-07-2022, 01:39 PM   #273
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,452
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
That works! Can more than one argument be set per template? e.g. swapping "#aaaa" for "colourA" and then setting that in the external template.
You can pass as many arguments as you want. You can also set it up so that arguments have default values. See the docs.
chaley is offline   Reply With Quote
Old 01-08-2022, 08:36 PM   #274
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,037
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I've got it.

Code:
program:

arguments(date, colourA, colourB, colourC);
now = format_date(today(), 'yyyy-MM-dd');

		if days_between(now,date) <= '1' then colourA
		elif days_between(now,date) <= '7' then colourB
		elif days_between(now,date) <= '14' then colourC fi
Code:
program:
    colours_daysbetween($#lastread, '#1c7eff', '#538fff', '#2b5aa2')
(or I could use (colourA='#1c7eff'), thoughI'm not sure there's any reason to do this unless I add more variables)

Last edited by ownedbycats; 01-08-2022 at 08:39 PM.
ownedbycats is online now   Reply With Quote
Old 01-09-2022, 12:17 AM   #275
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,037
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
edit: whoops, figured it out
ownedbycats is online now   Reply With Quote
Advert
Old 01-09-2022, 07:09 AM   #276
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,452
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
I've got it.

Code:
program:

arguments(date, colourA, colourB, colourC);
now = format_date(today(), 'yyyy-MM-dd');

		if days_between(now,date) <= '1' then colourA
		elif days_between(now,date) <= '7' then colourB
		elif days_between(now,date) <= '14' then colourC fi
As you know that days_between() returns a number, I suggest you use numeric comparisons. That will avoid problems caused by the order of the tests. For example, using string comparisons '14' is less than '7'.

Try this:
Code:
program:

arguments(date, colourA, colourB, colourC);
		now = format_date(today(), 'yyyy-MM-dd');
		days = days_between(now,date);

		if days <=# 1 then colourA
		elif days <=# 7 then colourB
		elif days <=# 14 then colourC fi
chaley is offline   Reply With Quote
Old 01-09-2022, 12:18 PM   #277
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,037
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Yes I'll fix that.

Someone I know was learning Python and their program told them that the double of '5' was '55.' Which is correct... if you want to double the string '5' instead of the integer '5.'
ownedbycats is online now   Reply With Quote
Old 01-09-2022, 11:13 PM   #278
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,037
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Question: Is undefined the same as '0' in a days_between?

Code:
program:

	read = $$#lastread;
	updated = $$#fanficupdated;

	if $$#percentread <# 100 && days_between (read, updated) <=# 0 then '#ffff7f'  fi
This activates on books that have an undefined #fanficupdated, though if I change it to <#0 that fixes it.
ownedbycats is online now   Reply With Quote
Old 01-10-2022, 05:24 AM   #279
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,452
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Question: Is undefined the same as '0' in a days_between?

Code:
program:

	read = $$#lastread;
	updated = $$#fanficupdated;

	if $$#percentread <# 100 && days_between (read, updated) <=# 0 then '#ffff7f'  fi
This activates on books that have an undefined #fanficupdated, though if I change it to <#0 that fixes it.
days_between() returns the empty string if either parameter isn't a date. Numeric comparison treats the empty string as zero, which is why the comparison succeeds.

I suggest that you don't depend on that, instead being explicit about what happens if dates are undefined. There are at least two ways to do it. The first is to use raw_field() with a default, for example
Code:
	read = raw_field('#lastread', today());
which sets read to today() if #lastread is undefined. You can of course put any date you want for the default.

Another way, one that I prefer, is to test if the two dates are defined and do something explicit. Something like this:
Code:
program:

	read = $$#lastread;
	updated = $$#fanficupdated;

	if read == 'none' || updated == 'none' then
		'#090909'
	elif $$#percentread <# 100 && days_between (read, updated) <=# 0 then 
		'#ffff7f' 
	fi
or this
Code:
program:

	read = $$#lastread;
	updated = $$#fanficupdated;

	if read == 'none' || updated == 'none' then
		days = -1
	else
		days = days_between (read, updated)
	fi;

	if $$#percentread <# 100 && days <=# 0 then 
		'#ffff7f' 
	fi

Last edited by chaley; 01-10-2022 at 03:34 PM. Reason: Fix typo
chaley is offline   Reply With Quote
Old 01-10-2022, 03:08 PM   #280
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,037
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Yes, I was thinking of adding a test. Though just keeping it <# would work too for this specific case; I was checking that #fanficupdated was newer than #lastread (e.g. when a fanfic updates and I haven't read the new chapter yet).
ownedbycats is online now   Reply With Quote
Old 01-11-2022, 09:56 PM   #281
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,037
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Question: When using a stored template that returns 'True' if it matches certain criteria (psuedobools), I noticed these work the same:

Code:
program:
	if stored_returnstrueifvalid() == 'True' then 'output' fi
Code:
program:
	if stored_returnstrueifvalid() then 'output' fi
When do I need I keep the "== 'True'" bit?

Also, is there any good way to test two templates getting same results on a set of books aside from shuffling it between the tester and Notepad? I don't believe there's a way to have two tester instances open.

Last edited by ownedbycats; 01-11-2022 at 10:31 PM.
ownedbycats is online now   Reply With Quote
Old 01-12-2022, 04:16 AM   #282
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,452
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Question: When using a stored template that returns 'True' if it matches certain criteria (psuedobools), I noticed these work the same:

Code:
program:
	if stored_returnstrueifvalid() == 'True' then 'output' fi
Code:
program:
	if stored_returnstrueifvalid() then 'output' fi
When do I need I keep the "== 'True'" bit?
A conditional expression is False if it evaluates to the empty string, otherwise it is True. As such you don't need the == 'True' part if the stored template return that or the empty string.
Quote:
Also, is there any good way to test two templates getting same results on a set of books aside from shuffling it between the tester and Notepad? I don't believe there's a way to have two tester instances open.
Some ways:
  • You could use calibre-debug -g to have a cmd window, then use the template print() to show values in that window.
  • If they are stored templates then you can compare their results in a third template.
  • You can create a few extra composite columns and compare the values stored in the columns.

Last edited by chaley; 01-22-2022 at 03:45 PM. Reason: Grammar
chaley is offline   Reply With Quote
Old 01-13-2022, 02:42 AM   #283
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,037
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Thanks

I came across some strange behaviour with a new template (ignore the wonky indenting, I removed a lot of other if-thens):

Code:
program:
f = re($#chapters, '(.*)/.*', '\1');
s = re($#chapters, '.*/(.*)', '\1');
newpercent = round(multiply ((f / s), 100));
 
					if newpercent < 99 then newpercent 
						else 98
					fi

Basically:

Divide F by S. Multiply it by 100. Round it to the nearest digit. If the number less than 99, use the new number; otherwise set it to 98.

But on line 6 if I add a '#' to if newpercent < #98 for the numeric comparison I get this error:

Code:
EXCEPTION:  Formatter: Failed to scan program. Invalid input '#99 then newpercent \n\t\t\t\t\t\telse 98\n\t\t\t\t\tfi' near the end of the program
It works fine if I use it without the #. Did I make a syntax mistake?

EDIT: I misplaced a space. It should've been <# not < #.

Last edited by ownedbycats; 01-13-2022 at 03:10 AM.
ownedbycats is online now   Reply With Quote
Old 01-13-2022, 04:53 AM   #284
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,452
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
EDIT: I misplaced a space. It should've been <# not < #.
And it works like that, yes?

You really do want to use <#. Without it the comparison uses lexicographical order where 100 < 99.
chaley is offline   Reply With Quote
Old 01-13-2022, 05:12 AM   #285
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,037
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Yes it works.
ownedbycats is online now   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 225 08-04-2025 06:31 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 07:24 AM.


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