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 02-18-2023, 11:53 AM   #511
dunhill
Guru
dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.
 
dunhill's Avatar
 
Posts: 724
Karma: 228142
Join Date: Sep 2017
Location: Argentina
Device: moon+ reader, kindle paperwhite
mistake in formula
I have a column with date read finished
I want to know what month it is in another column. So I created a column that depended on another and in the template I put it like this:
{#column name:'test($, strcat(format_date($,'mmm')),'Without date')'}

As a result I get Without date, 000 or Bad date.
How could I get the month that is in this way Jan, Feb, Mar
dunhill is offline   Reply With Quote
Old 02-18-2023, 12:10 PM   #512
dunhill
Guru
dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.
 
dunhill's Avatar
 
Posts: 724
Karma: 228142
Join Date: Sep 2017
Location: Argentina
Device: moon+ reader, kindle paperwhite
Quote:
Originally Posted by dunhill View Post
mistake in formula
I have a column with date read finished
I want to know what month it is in another column. So I created a column that depended on another and in the template I put it like this:
{#column name:'test($, strcat(format_date($,'mmm')),'Without date')'}

As a result I get Without date, 000 or Bad date.
How could I get the month that is in this way Jan, Feb, Mar
I answer myself
The month must be capital letter (MMM) but I did not discover why I get Bad Date
dunhill is offline   Reply With Quote
Advert
Old 02-18-2023, 01:19 PM   #513
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: 11,752
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
You don't say what a "bad date" looks like when showing in the booklist or book details. Because you are using a printable date (the value of '#column name') the month names will be localized. The date functions in calibre are localized to accept 3-letter month names in English, French, and German. See replace_months() in calibre's source calibre.utils.date.

I expect in your case the month abbreviations are in Spanish. In that language many 3-letter month abbreviations are the same as in English, but several differ from their English equivalents such as "abr" instead of "Apr"

You avoid this problem by using raw_field to get the date in ISO-format instead of localized. Something like this, replacing '#mydate' with the real lookup name:
Code:
{:'ifempty(format_date(raw_field('#mydate', ''), 'MMM'), 'Without date')'}
or this, which is more like your original.
Code:
{:'d = raw_field('#mydate', ''); test(d, strcat(format_date(d,'MMM')),'Without date')'}
Note: if this is the only template in the composite column then I suggest you use General Program Mode, as that will be faster because of template caching. Something like this:
Code:
program: ifempty(format_date(raw_field('#mydate', ''), 'MMM'), 'Without date')
Or even faster: a Python template:
Code:
python:
def evaluate(book, context):
	d = book.get('#mydate')
	if d is None:
		return 'Without date'
	# Localize these as you wish
	months = ['ene', 'feb', 'mar', 'abr', 'may', 'jun', 
		  'jul', 'ago', 'sep', 'oct', 'nov', 'dic']
	return months[d.month-1]

Last edited by chaley; 02-18-2023 at 01:59 PM. Reason: Grammar
chaley is offline   Reply With Quote
Old 02-18-2023, 01:21 PM   #514
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: 8,685
Karma: 62000001
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Is this the only way to check that #timedatecolumn1 is newer than #timedatecolumn2?

Code:
days_between($$#timedatecolumn1, $$#timedatecolumn2) >#0
ownedbycats is online now   Reply With Quote
Old 02-18-2023, 01:32 PM   #515
dunhill
Guru
dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.
 
dunhill's Avatar
 
Posts: 724
Karma: 228142
Join Date: Sep 2017
Location: Argentina
Device: moon+ reader, kindle paperwhite
Quote:
Originally Posted by chaley View Post
You don't say what a "bad date" looks like when showing in the booklist or book details. Because you are using a printable date (the value of '#column name') the month names will be in localized. The date functions in calibre are localized to accept 3-letter month names in English, French, and German. See replace_months() in calibre's source calibre.utils.date.

I expect in your case the month abbreviations are in Spanish. In that language many 3-letter month abbreviations are the same as in English, but several differ from their English equivalents such as "abr" instead of "Apr"

You avoid this problem by using raw_field to get the date in ISO-format instead of localized. Something like this, replacing '#mydate' with the real lookup name:
Code:
{:'ifempty(format_date(raw_field('#mydate', ''), 'MMM'), 'Without date')'}
or this, which is more like your original.
Code:
{:'d = raw_field('#mydate', ''); test(d, strcat(format_date(d,'MMM')),'Without date')'}
Note: if this is the only template in the composite column then I suggest you use General Program Mode, as that will be faster because of template caching. Something like this:
Code:
program: ifempty(format_date(raw_field('#mydate', ''), 'MMM'), 'Without date')
Or even faster: a Python template:
Code:
python:
def evaluate(book, context):
	d = book.get('#mydate')
	if d is None:
		return 'Without date'
	# Localize these as you wish
	months = ['ene', 'feb', 'mar', 'abr', 'may', 'jun', 
		  'jul', 'ago', 'sep', 'oct', 'nov', 'dic']
	return months[d.month-1]



Brilliant !! thank you so much !!
dunhill is offline   Reply With Quote
Advert
Old 02-18-2023, 01:58 PM   #516
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: 11,752
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Is this the only way to check that #timedatecolumn1 is newer than #timedatecolumn2?

Code:
days_between($$#timedatecolumn1, $$#timedatecolumn2) >#0
No.

I assume either date can be undefined.

This one works because ISO formatted dates are comparable as strings as long as the dates are in the same timezone.
Code:
program:
	d1 = $$#mydate;
	d2 = $$date;
	if d1 == 'None' || d2 == 'None' then return '' fi;
	if d1 < d2 then 'yes' fi
An alternate way that uses timestamps, which should work with differing timezones but might have problems with dates previous to "the epoch" (1970 IIRC):
Code:
program:
	d1 = $$#mydate;
	d2 = $$date;
	if d1 == 'None' || d2 == 'None' then return '' fi;
	d1 = format_date($#mydate, 'to_number');
	d2 = format_date($date, 'to_number');
	if d1 <# d2 then 'yes' fi
Or a Python template that works with timezones:
Code:
python:
def evaluate(book, context):
	d1 = book.get('#mydate')
	d2 = book.get('timestamp')
	if d1 is None or d2 is None:
		return '' # return no if either date isn't defined
	return 'Yes' if d1 < d2 else ''
chaley is offline   Reply With Quote
Old 02-23-2023, 05:06 PM   #517
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: 8,685
Karma: 62000001
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
If I have no book selected when I go into template functions, I get a generic 'title' book. What are the values of this book?

Also, is it intended that it fails on functions that only work in GUI? approximate_formats is one.

Last edited by ownedbycats; 02-23-2023 at 05:09 PM.
ownedbycats is online now   Reply With Quote
Old 02-23-2023, 05:37 PM   #518
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: 8,685
Karma: 62000001
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Additionally, I updated my #kobocoll generation template again to resolve a Kobo glitch (tl;dr: too many books in a collection causes sync to stall):

Code:
program:
	genre = $#subjects;
	colls = strcat(	
##		$#booktype, ',',
##		if $$#purchasecost == '0.00' then 'Freebies,' fi,
		if 'Omnibus' in $#admintags then 'Omnibuses,' fi,
		if 'overdrive' in approximate_formats() && !'formerlibrary' in $#admintags then 'Loans,' fi, 
		if $#booktype=='Fanfiction' then list_re($tags, ',', '^Fanfiction.(.*)$', 'Fanfiction: \1,') fi,
		if '^Cozy Mystery$' inlist genre then 'Cozy Mysteries,' fi,
		if '^Horses$' inlist genre then 'Horses,' fi,
		if '^(Science Fiction)' inlist genre then 'Science Fiction,' fi,
		if '^(Fantasy|Paranormal)$' inlist genre then 'Fantasy & Paranormal,' fi,
);

	if colls == '' then colls == strcat($#booktype, ',') fi;

	new_colls = list_union($#kobocoll, colls, ',')
I'm trying to make it so that

a) Define whatever the strcat returns as 'colls'
b) if strcat returns nothing and 'colls' is empty, define #booktype and a comma as 'colls'
c) Merge colls with the existing column (taglike).

It's not working for me though; I just get a blank result. I also tried !colls with the same result. I thought of enclosing it in a switch_if but wasn't sure what to put as the first test_expression.

Last edited by ownedbycats; 02-23-2023 at 06:39 PM.
ownedbycats is online now   Reply With Quote
Old 02-23-2023, 05:57 PM   #519
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: 8,685
Karma: 62000001
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Third question: Is there some sort of recursion protection in stored templates? I added columnupdate_kobocoll() (the name of the stored template I'm editing) to the strcat just
because I like trying to break things to see what would happen and got the same results.
ownedbycats is online now   Reply With Quote
Old 02-23-2023, 09:07 PM   #520
isarl
Addict
isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.
 
Posts: 287
Karma: 2534928
Join Date: Nov 2022
Location: Canada
Device: Kobo Aura 2
Quote:
Originally Posted by ownedbycats View Post
Code:
if colls == '' then colls == strcat($#booktype, ',') fi;
Replace the second double equals sign in this line with a single equals sign. Does your template work now?
isarl is offline   Reply With Quote
Old 02-23-2023, 09:20 PM   #521
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: 8,685
Karma: 62000001
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Yes. Silly mistake.
ownedbycats is online now   Reply With Quote
Old 03-03-2023, 12:45 AM   #522
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: 8,685
Karma: 62000001
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
When short-circuiting is accounted for, would it maybe be faster to do two separate exact checks:

Code:
($#columnname=='foo'||$#columnname=='bar')
Than one regex match?

Code:
'^(foo|bar)$' in $#columnname

Last edited by ownedbycats; 03-03-2023 at 01:09 AM.
ownedbycats is online now   Reply With Quote
Old 03-03-2023, 05:48 AM   #523
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: 11,752
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
When short-circuiting is accounted for, would it maybe be faster to do two separate exact checks:

Code:
($#columnname=='foo'||$#columnname=='bar')
Than one regex match?

Code:
'^(foo|bar)$' in $#columnname
In this case and assuming that the first check is true a reasonable number of times, then yes because the == operator is much faster than the 'in' operator.
chaley is offline   Reply With Quote
Old 03-12-2023, 01:09 AM   #524
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: 8,685
Karma: 62000001
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
New question: I have this template that populates my Kobo collections column. (Non-composite, Action Chains single-field edit).

Code:
program:
	genre = $#subjects;
	colls = strcat(	
##		if $$#purchasecost == '0.00' then 'Freebies,' fi,
		if 'Omnibus' in $#admintags then 'Omnibuses,' fi,
		if 'overdrive' in approximate_formats() && !$purchasesource then 'Loans,' fi, 
		if $#booktype=='Fanfiction' then list_re($tags, ',', '^Fanfiction.(.*)$', 'Fanfiction: \1,') fi,
		if 'public domain' inlist $#admintags then 'Public Domain,' fi,
		if '^Cozy Mystery$' inlist genre then 'Cozy Mysteries,' fi,
		if '^Horses$' inlist genre then 'Horses,' fi,
		if 'Folktales & Mythology' inlist genre then 'Folktales & Mythology,' fi,
		if '^Science Fiction$' inlist genre then 'Science Fiction,' fi,
		if '^(Fantasy|Paranormal)$' inlist genre then 'Fantasy & Paranormal,' fi,
	);

	if colls == '' then colls = strcat($#booktype, ',') fi;

	new_colls = list_union($#kobocoll, colls, ',')
The strcat lines generates various entries, line 16 fallsback to #booktype if there's nothing generated, and line 18 merges with the existing entries. (Being able to add additional entries for individual books is why I don't use a composite column here.)

Sometimes this merging results in leftover #booktype entries, due to my workflow (running the column update when there's a #booktype but no #subjects). Less common, but also happens when adding a new entry to the strcat and bulk-updating.

A real example:
A book with 'Fiction' in #booktype, 'Science Fiction' in #subjects, and an existing #kobocoll value of 'Fiction'
colls returns 'Science Fiction'
new_colls then produces 'Fiction, Science Fiction'

What is the best way to remove 'Fiction' from this without it getting merged back in? A list_difference, but I'm having trouble figuring out what order to put things in

Last edited by ownedbycats; 03-12-2023 at 03:15 AM.
ownedbycats is online now   Reply With Quote
Old 03-12-2023, 04:43 AM   #525
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: 11,752
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
New question: I have this template that populates my Kobo collections column. (Non-composite, Action Chains single-field edit).
It is very hard to know how to "fix" this without knowing the universe of possibilities.

The following works for your example. I don't know if it will work in general. It removes any value in #booktype from #kobocol before merging, which seems to be what you are looking for.
Code:
new_colls = list_union(list_difference($#kobocol, $#booktype, ','), colls, ',')
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 150 Yesterday 09:38 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 11:10 PM.


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