![]() |
#286 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,082
Karma: 76037135
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
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 Last edited by ownedbycats; 01-13-2022 at 07:19 PM. |
![]() |
![]() |
![]() |
#287 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,475
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
ao3:1, goodreads:16967, uri:https://archiveofourown/works/12345, x:y Spoiler:
then the result is Code:
goodreads:16967, uri:https://archiveofourown/works/12345, x:y FWIW: the Code:
n = re(u, '^^https://standardebooks.org/ebooks/()', '\1'); Code:
n = re(u, '^https://standardebooks.org/ebooks/(.*)$', '\1'); |
|
![]() |
![]() |
Advert | |
|
![]() |
#288 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,082
Karma: 76037135
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
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: If I take out the check for 'standard', it works: 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 02:01 AM. |
![]() |
![]() |
![]() |
#289 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,475
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
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. |
|
![]() |
![]() |
![]() |
#290 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,082
Karma: 76037135
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
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. |
![]() |
![]() |
Advert | |
|
![]() |
#291 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,082
Karma: 76037135
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
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, ) 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 06:51 PM. |
![]() |
![]() |
![]() |
#292 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,475
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
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, ',') Code:
x = list_union(list1, list_union(list2, list3, ','), ',') |
![]() |
![]() |
![]() |
#293 |
Junior Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5
Karma: 31954
Join Date: May 2020
Location: Canada
Device: Kindle PW4 (2018)
|
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):
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. |
![]() |
![]() |
![]() |
#294 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,475
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
As far as I can see, your choices are:
|
|
![]() |
![]() |
![]() |
#295 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,082
Karma: 76037135
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
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 Last edited by ownedbycats; 01-21-2022 at 04:16 AM. |
![]() |
![]() |
![]() |
#296 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,475
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
s = re($#chapters, '.*/(.*)', '\1') 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. |
|
![]() |
![]() |
![]() |
#297 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,082
Karma: 76037135
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
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 04:48 AM. |
![]() |
![]() |
![]() |
#298 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,082
Karma: 76037135
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
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 Last edited by ownedbycats; 01-21-2022 at 05:24 AM. |
![]() |
![]() |
![]() |
#299 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,475
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
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 |
|
![]() |
![]() |
![]() |
#300 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,082
Karma: 76037135
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
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.
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Library Management: various questions not worth their own thread | ownedbycats | Library Management | 234 | Today 05:42 AM |
[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 |