Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 01-13-2022, 08:13 PM   #286
ownedbycats
Wizard
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by 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: 3,399
Karma: 14100982
Join Date: Oct 2018
Device: Kobo Aura HD (retired), Kobo Libra H2O
Code:
program:
	publisher = $publisher;
	ids = $identifiers;
	u = select(ids, 'url');
	s = select(ids, 'standard');

	if publisher == 'Standard Ebooks' && u != s then
		n = re(u, '^^https://standardebooks.org/ebooks/()', '\1');
		ids = list_union(ids, strcat('standard:', n), ',')
	fi;

	if publisher == 'Standard Ebooks' && u && s then
		ids = list_difference(ids, strcat('url:', u), ',')
	fi;
	ids
In an Action Chain, if I run this once, it produces the standardidentifier and does not delete the url: identifier. If I run it on a book that has both standard and url: identifiers it does delete the url:. Do I need to make it two separate actions/templates?

Last edited by ownedbycats; 01-13-2022 at 08:19 PM.
ownedbycats is offline   Reply With Quote
Old 01-14-2022, 08:10 AM   #287
chaley
Grumpy old git
chaley ought to be getting tired of karma fortunes 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.
 
chaley's Avatar
 
Posts: 10,109
Karma: 3858661
Join Date: Jan 2010
Location: UK
Device: Reader
Quote:
Originally Posted by ownedbycats View Post
[...]
In an Action Chain, if I run this once, it produces the standardidentifier and does not delete the url: identifier. If I run it on a book that has both standard and url: identifiers it does delete the url:. Do I need to make it two separate actions/templates?
I verified that an Action Chains single field edit will replace the ids with the result of the template. Example: given identifiers of
Code:
ao3:1, goodreads:16967, uri:https://archiveofourown/works/12345, x:y
and the action chain
Spoiler:
Code:
{
  "ActionsChainMenus": {
    "Menus": [
      {
        "active": true,
        "chain_settings": {
          "chain_links": [
            {
              "action_name": "Single Field Edit",
              "action_settings": {
                "col_name": "identifiers",
                "template": "program:\n\tlist_difference($identifiers, 'ao3:1', ',')",
                "value_type": "template"
              },
              "comment": ""
            }
          ],
          "refresh_gui": true
        },
        "image": "",
        "menuText": "Test identifiers",
        "subMenu": ""
      }
    ]
  },
  "schemaVersion": 1.8
}

then the result is
Code:
goodreads:16967, uri:https://archiveofourown/works/12345, x:y
The ao3:1 identifier is removed. I can't say why it doesn't work for you. I suggest you put print() statements in it so you can verify exactly the result of the template.

FWIW: the
Code:
n = re(u, '^^https://standardebooks.org/ebooks/()', '\1');
is strange. The \1 will always result in the empty string because the grouping () contains no pattern, so why is it there? I also don't know why there are two ^ anchors in the front. I think you mean
Code:
n = re(u, '^https://standardebooks.org/ebooks/(.*)$', '\1');
chaley is offline   Reply With Quote
Old 01-14-2022, 10:38 PM   #288
ownedbycats
Wizard
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by 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: 3,399
Karma: 14100982
Join Date: Oct 2018
Device: Kobo Aura HD (retired), Kobo Libra H2O
I was having trouble with the regex and basically just put in the first thing that actually halfway worked.

Oddly, template tester isn't removing the url: identifier either:

Click image for larger version

Name:	2022-01-14 22_32_48-Template tester.png
Views:	18
Size:	39.4 KB
ID:	191593

If I take out the check for 'standard', it works:

Click image for larger version

Name:	2022-01-14 22_38_15-Template tester.png
Views:	18
Size:	37.6 KB
ID:	191595

Is it looking at the state of the column at the beginning of the template, when it only has the url identifier? That would explain why it works running it a second time.

Last edited by ownedbycats; 01-15-2022 at 03:01 AM.
ownedbycats is offline   Reply With Quote
Old 01-15-2022, 06:12 AM   #289
chaley
Grumpy old git
chaley ought to be getting tired of karma fortunes 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.
 
chaley's Avatar
 
Posts: 10,109
Karma: 3858661
Join Date: Jan 2010
Location: UK
Device: Reader
Quote:
Originally Posted by ownedbycats View Post
I was having trouble with the regex and basically just put in the first thing that actually halfway worked.

Oddly, template tester isn't removing the url: identifier either:

Attachment 191593

If I take out the check for 'standard', it works:

Attachment 191595

Is it looking at the state of the column at the beginning of the template, when it only has the url identifier? That would explain why it works running it a second time.
It is looking at the value of "s", which is the result of the select() on line 5. It doesn't see any changes you make to "ids" after line 5.

However, I suspect your logic won't do what you want. If s is non-empty then there is a "standard" identifier. If s != u then you add a standard identifier, which is probably different from the original so there are now 2 of them in the list. When you save the identifiers calibre will pick one of them; which one is undefined. Thus if s is non-empty then you must remove the existing "standard" identifier before adding a different "standard" identifer.

Once you have done the above the rest of your logic assumes that 's' contains the current value of the "standard" identifier. Your template must ensure that is the case, perhaps by assigning to 's'.

Depending on what you are doing it might be easier and less buggy to loop through the identifiers, building a new identifiers list.
chaley is offline   Reply With Quote
Old 01-15-2022, 08:14 AM   #290
ownedbycats
Wizard
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by 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: 3,399
Karma: 14100982
Join Date: Oct 2018
Device: Kobo Aura HD (retired), Kobo Libra H2O
For now, I think I'll just remove the check for the standard: identifier. I could probably also remove the check for url: too.

Unrelated comment: Using stored templates for complex checks cuts down a lot on if-then-fi placement mistakes.
ownedbycats is offline   Reply With Quote
Old 01-16-2022, 07:07 PM   #291
ownedbycats
Wizard
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by 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: 3,399
Karma: 14100982
Join Date: Oct 2018
Device: Kobo Aura HD (retired), Kobo Libra H2O
I'm having some trouble with using an inlist with square brackets, e.g.

Code:
program:
coll = $#kobocoll;

first_non_empty
   (
	if '[Send to Device]' inlist coll then 'sync.png' fi,
	if "[Kobo Store]" inlist coll then 'drm-locked.png' fi,
   )
incorrectly marks every book with sync.png (and if I comment the line out, then drm-locked.png). It doesn't happen if I remove the square brackets. Technically it's still working as it's not exact and still matches, but what is going on?

EDIT: I think I know what's happening. I forgot about regex. Putting in slashes to.... break (I forgot the actual word) them makes it work.

EDIT: Is there a better way to merge three lists then this? I'm a bit surprised that list_union doesn't handle more than 2 lists.

Code:
new_entries = list_union(first_list, second_list, ',';
new_list = list_union(new_entries, third_list, ',')

Last edited by ownedbycats; 01-16-2022 at 07:51 PM.
ownedbycats is offline   Reply With Quote
Old 01-16-2022, 08:14 PM   #292
chaley
Grumpy old git
chaley ought to be getting tired of karma fortunes 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.
 
chaley's Avatar
 
Posts: 10,109
Karma: 3858661
Join Date: Jan 2010
Location: UK
Device: Reader
As you determined, you need to use backslashes to escape the square brackets that indicate character classes in regular expressions.

The list_union() function takes two lists. If you need to do a union of more than two lists then you do
Code:
    x = list_union(list1, list2, ',');
    x = list_union(list3, x, ',')
etc, or
Code:
    x = list_union(list1, list_union(list2, list3, ','), ',')
chaley is offline   Reply With Quote
Old 01-20-2022, 04:59 PM   #293
SLaSZT
Junior Member
SLaSZT began at the beginning.
 
Posts: 1
Karma: 10
Join Date: May 2020
Location: Canada
Device: Paperwhite 2018 (8GB, Wifi)
Custom sort of a custom column?

Maybe a dumb question, but how can I set up a custom sort of a custom column? I literally just realized today that custom columns are a thing so I don't know if there's simple code that already does this.

I have a custom column called Status that contains the fixed text values of Reading, Priority, Paused, and Read. I'd like them to sort in that order (descending):
  1. Reading
  2. Priority
  3. Paused
  4. Read

Right now, it seems to be sorting alphabetically. I think that I could probably force it to sort the way I want by explicitly numbering them, but I don't want to have that numbering visible in the column.

Thanks in advance.
SLaSZT is offline   Reply With Quote
Old 01-20-2022, 05:41 PM   #294
chaley
Grumpy old git
chaley ought to be getting tired of karma fortunes 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.
 
chaley's Avatar
 
Posts: 10,109
Karma: 3858661
Join Date: Jan 2010
Location: UK
Device: Reader
Quote:
Originally Posted by SLaSZT View Post
Maybe a dumb question, but how can I set up a custom sort of a custom column? I literally just realized today that custom columns are a thing so I don't know if there's simple code that already does this.

I have a custom column called Status that contains the fixed text values of Reading, Priority, Paused, and Read. I'd like them to sort in that order (descending):
  1. Reading
  2. Priority
  3. Paused
  4. Read

Right now, it seems to be sorting alphabetically. I think that I could probably force it to sort the way I want by explicitly numbering them, but I don't want to have that numbering visible in the column.

Thanks in advance.
You can't set a custom sort. A column is sorted depending on its type. Text columns will sort alphabetically.

As far as I can see, your choices are:
  • Pick words that you understand their meaning and that sort the way you want. It seems that if you replace "Read" with "Finished" then you have your sort.
  • Prefix with numbers or characters that make it sort the way you want.
  • Use two columns, one that sorts correctly and a "column built from other columns" that displays the text you want based on the first column's value.
chaley is offline   Reply With Quote
Old 01-21-2022, 03:02 AM   #295
ownedbycats
Wizard
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by 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: 3,399
Karma: 14100982
Join Date: Oct 2018
Device: Kobo Aura HD (retired), Kobo Libra H2O
When I run the following template on a book that has "Not Set" in my #chapters (composite) column, it gives me EXCEPTION: could not convert string to float: 'Not Set'.

I thought that the check on line 7 would prevent it. Did I make a mistake and leave out an else or misunderstand the != compare?

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

	if 
		$#chapters != 'Not Set'
			then 
## updates #percentread for updated fanfics comparing no. of read chapters to total. 
## fanfic_unreadchaps() check for unread chaps based on kobo bookmark.
				if and(
					fanfic_unreadchaps(),
					$$#percentread ==#100,
					) 
					then 
						if 
							newpercent <#99 
						then 
							newpercent
						else 
							98 
						fi 
				else 
					$$#percentread
				fi

		else $$#percentread
	fi
EDIT: Commenting out line four makes it return #percentread (expected result). Was it trying to do math even if there was nothing matching for f and s? I guess I need to fix the newpercent bit somehow or rearrange the template so that lines 2-4 run after the 'not set' check.

Last edited by ownedbycats; 01-21-2022 at 05:16 AM.
ownedbycats is offline   Reply With Quote
Old 01-21-2022, 05:20 AM   #296
chaley
Grumpy old git
chaley ought to be getting tired of karma fortunes 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.
 
chaley's Avatar
 
Posts: 10,109
Karma: 3858661
Join Date: Jan 2010
Location: UK
Device: Reader
Quote:
Originally Posted by ownedbycats View Post
EDIT: Commenting out line four makes it return #percentread (expected result). Was it trying to do math even if there was nothing matching for f and s? I guess I need to fix the newpercent bit somehow or rearrange the template so that lines 2-4 run after the 'not set' check.
The re() function isn't doing what you think it does. If the regular expression in
Code:
s = re($#chapters, '.*/(.*)', '\1')
matches nothing then s is assigned the value of $#chapters. You need to account for what happens if the pattern doesn't match the value. One way to do it is to verify that there is a '/' in $#chapters before extracting the values and doing the computation.

Yes, it will try to do the math with the values in s and f no matter what those values are.

You can use the debugger and breakpoints to look at the values of the variables and expressions to better get a handle on what your template is doing.
chaley is offline   Reply With Quote
Old 01-21-2022, 05:26 AM   #297
ownedbycats
Wizard
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by 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: 3,399
Karma: 14100982
Join Date: Oct 2018
Device: Kobo Aura HD (retired), Kobo Libra H2O
Yes I was looking at my fanfic_unreadchaps() as it was similar and for that one I had it check that '/' was present -- there might be a better way but it was simple and accurate enough. So either I can insert that check or move lines 2-4 further down, perhaps below the unreadchap check itself.

EDIT: I found it easier to move the lines. Also tweaked the unreadchaps code to return the number instead of just 'true' -- isn't much effort to change existing templates and might be useful to have the exact number.

Code:
program:

	if 
		$#chapters != 'Not Set'
			then 
				if and(
						fanfic_unreadchaps() >=# 1,
						$$#percentread ==#100,
						) 
					then 
						f = re($#chapters, '(.*)/.*', '\1');
						s = re($#chapters, '.*/(.*)', '\1');
						newpercent = round(multiply ((f / s), 100));
					
						if newpercent <#99 then newpercent
						else 98 
						fi 
				else 
					$$#percentread
				fi

		else $$#percentread
	fi

Last edited by ownedbycats; 01-21-2022 at 05:48 AM.
ownedbycats is offline   Reply With Quote
Old 01-21-2022, 05:56 AM   #298
ownedbycats
Wizard
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by 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: 3,399
Karma: 14100982
Join Date: Oct 2018
Device: Kobo Aura HD (retired), Kobo Libra H2O
Okay, here's something semi-related to the last one:

Code:
program:
	if $#fanficcat && '/' in $#chapters then
		f = re($#chapters, '(.*)/.*', '\1');
		s = re($#chapters, '.*/(.*)', '\1');
		if s - f >=# 1 then s - f fi
	fi
Is there a less kludgey way to handle line 5 so that '0' returns an empty value?

Last edited by ownedbycats; 01-21-2022 at 06:24 AM.
ownedbycats is offline   Reply With Quote
Old 01-21-2022, 06:26 AM   #299
chaley
Grumpy old git
chaley ought to be getting tired of karma fortunes 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.
 
chaley's Avatar
 
Posts: 10,109
Karma: 3858661
Join Date: Jan 2010
Location: UK
Device: Reader
Quote:
Originally Posted by ownedbycats View Post
Okay, here's something semi-related to the last one:

Code:
program:
	if $#fanficcat && '/' in $#chapters then
		f = re($#chapters, '(.*)/.*', '\1');
		s = re($#chapters, '.*/(.*)', '\1');
		if s - f >=# 1 then s - f fi
	fi
Is there a less kludgey way to handle line 5 so that '0' returns an empty value (e.g. if fanfic_unreadchaps() then 'output' type things)
What I would do is:
Code:
program:
	res = '';
	if $#fanficcat && '/' in $#chapters then
		f = re($#chapters, '(.*)/.*', '\1');
		s = re($#chapters, '.*/(.*)', '\1');
		if s > f then
			res = s - f
		fi
	fi
You can get rid of 'res' if the result of the template is the value of the if
chaley is offline   Reply With Quote
Old 01-21-2022, 09:32 PM   #300
ownedbycats
Wizard
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by 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: 3,399
Karma: 14100982
Join Date: Oct 2018
Device: Kobo Aura HD (retired), Kobo Libra H2O
That works. I didn't realize it was possible to re-use a variable name and have it return different things. That will be useful to know.
ownedbycats is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A few questions... (template language, mainly) Clem2605 Library Management 2 12-30-2020 04:25 AM
Questions on Kobo [Interfered with another thread topic] spdavies Kobo Reader 8 10-12-2014 12:37 PM
[OLD Thread] Some questions before buying the fire. darthreader13 Kindle Fire 7 05-10-2013 10:19 PM
[Old Thread] Save Template not working TGinAZ Calibre 7 01-18-2012 02:03 AM
Thread management questions meme Feedback 6 01-31-2011 06:07 PM


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


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