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 03-12-2023, 07:21 AM   #526
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,050
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I managed to figure this, perhaps a bit clumsily -- also changed some of the reference names to be a bit clearer

Code:
program:
	genre = $#subjects;
	new_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 new_colls == '' then existing_colls = $#kobocoll fi;
	if new_colls then existing_colls = list_difference($#kobocoll, $#booktype, ',') fi;

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

	merged_colls = list_union(new_colls, existing_colls, ',');
explanation:

new_colls generates a set of new collections with the strcat

existing_colls is taken from the existing #kobocoll value. If new_colls exists, it removes booktype from the list

If new_colls doesn't exist, it sets it to #booktype

merged_colls combines new_colls and existing_colls.

Last edited by ownedbycats; 03-12-2023 at 07:29 AM.
ownedbycats is offline   Reply With Quote
Old 03-12-2023, 07:44 AM   #527
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,460
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
I managed to figure this, perhaps a bit clumsily -- also changed some of the reference names to be a bit clearer

Code:
program:
...
	if new_colls == '' then existing_colls = $#kobocoll fi;
	if new_colls then existing_colls = list_difference($#kobocoll, $#booktype, ',') fi;

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

	merged_colls = list_union(new_colls, existing_colls, ',');
explanation:

new_colls generates a set of new collections with the strcat

existing_colls is taken from the existing #kobocoll value. If new_colls exists, it removes booktype from the list

If new_colls doesn't exist, it sets it to #booktype

merged_colls combines new_colls and existing_colls.
FWIW: this is a simplified version of what you wrote:
Code:
program:
...
	if !new_colls then 
		existing_colls = $#kobocoll;
		new_colls = $#booktype
	else
		existing_colls = list_difference($#kobocoll, $#booktype, ',')
	fi;
	merged_colls = list_union(new_colls, existing_colls, ',');
chaley is offline   Reply With Quote
Old 03-12-2023, 12:51 PM   #528
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,050
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
A bit easier to understand, too. Thanks
ownedbycats is offline   Reply With Quote
Old 03-25-2023, 10:41 AM   #529
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,050
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
New question: I have an enumerated column, #purchasesource. Four of these have related identifiers that often are downloaded during metadata downloads:

Amazon - amazon
Baen - baen
Barnes & Noble - barnesnoble
Kobo - kobo

I prefer to have the identifier only for the store I got it from. So I made this template to remove the extra ones:

1. I have a book with #purchasesource set to "Kobo." After a metadata download, the book has goodreads, isbn, barnesnoble, and kobo identifiers.
2. Purchasesource is not Barnes & Noble, so the second if-then removes the barnesnoble identifier.
3. Purchasesource is Kobo, so the third if-then doesn't remove the Kobo identifier.
4. It doesn't remove the goodreads or isbn identifiers.

If I run the same template on a book that has no #purchasesource, it removes all four of them. If no identifiers are removed, it just returns the original list.

Code:
program:

	if 
		!$#purchasesource=="Amazon"
		&& select($identifier, 'amazon')
	then
		list_difference ($identifier, strcat('amazon:', select($identifier, 'amazon')), ',')

	elif 
		!$#purchasesource=="Barnes & Noble"
		&& select($identifier, 'barnesnoble')
	then
		list_difference ($identifier, strcat('barnesnoble:', select($identifier, 'barnesnoble')), ',')

	elif 
		!$#purchasesource=="Kobo"
		&& select($identifier, 'kobo')
	then
		list_difference ($identifier, strcat('kobo:', select($identifier, 'kobo')), ',')
	
	elif 
		!$#purchasesource=="Baen"
		&& select($identifier, 'baen')
	then
		list_difference ($identifier, strcat('baen:', select($identifier, 'baen')), ',')
	fi
As it's basically just running the same if-then with different values, is there a better way to do this?


Last edited by ownedbycats; 03-25-2023 at 10:47 AM.
ownedbycats is offline   Reply With Quote
Old 03-25-2023, 11:10 AM   #530
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,460
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
If I run the same template on a book that has no #purchasesource, it removes all four of them. If no identifiers are removed, it just returns the original list.
This template should do what your template does. I haven't tried it because I didn't set up the columns and the data.

Code:
program:

	def do_one(ids, check_value, select_identifier):
		si = select($identifier, select_identifier);
		if 
			!$#purchasesource==check_value && si
		then
			return list_difference (ids, strcat(select_identifier, si), ',')
		fi;
		return $ids
	fed;

	ids = do_one($identifiers, "Amazon",'amazon');
	ids = do_one(ids, "Barnes & Noble", 'barnesnoble');
	ids = do_one(ids, "Kobo", 'kobo');
	ids = do_one(ids, "Baen", 'baen')
chaley is offline   Reply With Quote
Old 03-25-2023, 12:14 PM   #531
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,050
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I had to change line 10 to use $identifiers but it seems to work
ownedbycats is offline   Reply With Quote
Old 03-25-2023, 12:17 PM   #532
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,460
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
I had to change line 10 to use $identifiers but it seems to work
It should be the variable ids, not $ids or $identifiers
chaley is offline   Reply With Quote
Old 03-25-2023, 04:02 PM   #533
Lys
Groupie
Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.
 
Posts: 166
Karma: 727278
Join Date: Dec 2022
Location: Not in an English speaking country
Device: (Too many) Kobo(s)
I feel there's an easy solution to this, but I can't find it on my own, so I need a bit of help.

I have a column (genre) that I use as a hierarchical tag.
Some examples of data I have in this column are:

Fiction.Classics.English Literature
Fiction.Classics.French Literature
Fiction.Historical Novel.Country: India
Fiction.Fantasy

Then I have another column (genre_list) that separates genres using:

Quote:
list_remove_duplicates(re($#genre, '\.', ','), ',')
And so far so good.


Now, I would like to have another column that excludes some items from genre_list.
The items I would like to remove are the ones matching the pattern: "xxxx Literature" and "Country: xxxx"

I know I can use list_difference to exclude values, but the list with the excluded values is compared term by term.
Is there a way to do so without having to list beforehand all occurrences of Country: xxxx, Xxxx Literature, but using the pattern?

Lys is offline   Reply With Quote
Old 03-25-2023, 04:55 PM   #534
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,460
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Lys View Post
I feel there's an easy solution to this, but I can't find it on my own, so I need a bit of help.

I have a column (genre) that I use as a hierarchical tag.
Some examples of data I have in this column are:

Fiction.Classics.English Literature
Fiction.Classics.French Literature
Fiction.Historical Novel.Country: India
Fiction.Fantasy

Then I have another column (genre_list) that separates genres using:



And so far so good.


Now, I would like to have another column that excludes some items from genre_list.
The items I would like to remove are the ones matching the pattern: "xxxx Literature" and "Country: xxxx"

I know I can use list_difference to exclude values, but the list with the excluded values is compared term by term.
Is there a way to do so without having to list beforehand all occurrences of Country: xxxx, Xxxx Literature, but using the pattern?

I suspect that list_re() can do the job but it requires two steps. Example:
Code:
program:
	a = list_re($#genre, ',', '^(.* Literature|Country: .*)$', '');
	list_difference($#genre, a, ',')
The list_re() generates a list of items to remove, using a pattern I made up from your example. The list_difference() removes the matched items from #genre.
chaley is offline   Reply With Quote
Old 03-25-2023, 05:17 PM   #535
Lys
Groupie
Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.Lys ought to be getting tired of karma fortunes by now.
 
Posts: 166
Karma: 727278
Join Date: Dec 2022
Location: Not in an English speaking country
Device: (Too many) Kobo(s)
Quote:
Originally Posted by chaley View Post
I suspect that list_re() can do the job but it requires two steps. Example:
Code:
program:
	a = list_re($#genre, ',', '^(.* Literature|Country: .*)$', '');
	list_difference($#genre, a, ',')
The list_re() generates a list of items to remove, using a pattern I made up from your example. The list_difference() removes the matched items from #genre.
It worked like a charm
Lys is offline   Reply With Quote
Old 03-30-2023, 12:04 PM   #536
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,050
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
While trying to set up the template in #530 I found a failure point that I'm surprised I managed to miss:

Code:
program:

	if 
		!$#purchasesource=="Amazon"
		&& select($identifier, 'amazon')
	then
		list_difference ($identifier, strcat('amazon:', select($identifier, 'amazon')), ',')

	elif 
		!$#purchasesource=="Barnes & Noble"
		&& select($identifier, 'barnesnoble')
	then
		list_difference ($identifier, strcat('barnesnoble:', select($identifier, 'barnesnoble')), ',')

	elif 
		!$#purchasesource=="Kobo"
		&& select($identifier, 'kobo')
	then
		list_difference ($identifier, strcat('kobo:', select($identifier, 'kobo')), ',')
	
	elif 
		!$#purchasesource=="Baen"
		&& select($identifier, 'baen')
	then
		list_difference ($identifier, strcat('baen:', select($identifier, 'baen')), ',')
	fi
If it finds one unwanted identifier, it would then skip the rest. What should I use instead of if-thens?
ownedbycats is offline   Reply With Quote
Old 03-30-2023, 12:30 PM   #537
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,460
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
If it finds one unwanted identifier, it would then skip the rest. What should I use instead of if-thens?
If you want all the checks to be made then you should use a sequence of if-thens without the else. You would need to pass along the intermediate result.

NB: The template in #530 doesn't have the problem. For completeness, here is the version corrected for the error you mentioned in #531.
Code:
program:

	def do_one(ids, check_value, select_identifier):
		si = select(ids, select_identifier);
		if 
			!$#purchasesource==check_value && si
		then
			return list_difference (ids, strcat(select_identifier, si), ',')
		fi;
		return ids
	fed;

	ids = do_one($identifiers, "Amazon",'amazon');
	ids = do_one(ids, "Barnes & Noble", 'barnesnoble');
	ids = do_one(ids, "Kobo", 'kobo');
	ids = do_one(ids, "Baen", 'baen')
chaley is offline   Reply With Quote
Old 03-30-2023, 01:05 PM   #538
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,050
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I can't figure out what's going on -- it's failing on this one specific book. It has no #purchasesource but adding one doesn't seem to work.
Attached Thumbnails
Click image for larger version

Name:	2023-03-30 14_01_48-Template tester dialog number 1 (multiple template dialogs allowed).png
Views:	541
Size:	46.0 KB
ID:	200698  
ownedbycats is offline   Reply With Quote
Old 03-30-2023, 01:15 PM   #539
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,460
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
I can't figure out what's going on -- it's failing on this one specific book. It has no #purchasesource but adding one doesn't seem to work.
The function in the template I suggested is wrong (I think). It doesn't correctly construct the identifier for the list_difference().

Try this:
Code:
			return list_difference (ids, strcat(select_identifier, ':', si), ',')
The change is to put a colon between the identifier name and identifier value.

An alternate change that is a bit slower is
Code:
			return list_difference (ids, select(ids, select_identifier), ',')
It is slower because it repeats the select().
chaley is offline   Reply With Quote
Old 03-30-2023, 01:36 PM   #540
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,050
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
That works

Question: Rarely when updating a saved template, I get an error about it being duplicated when using it elsewhere. This disappears upon restart. Is this a known glitch?
ownedbycats 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 229 Today 06:41 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:43 PM.


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