02-18-2023, 11:53 AM | #511 |
Guru
Posts: 733
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 |
02-18-2023, 12:10 PM | #512 | |
Guru
Posts: 733
Karma: 228142
Join Date: Sep 2017
Location: Argentina
Device: moon+ reader, kindle paperwhite
|
Quote:
The month must be capital letter (MMM) but I did not discover why I get Bad Date |
|
Advert | |
|
02-18-2023, 01:19 PM | #513 |
Grand Sorcerer
Posts: 11,778
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')'} Code:
{:'d = raw_field('#mydate', ''); test(d, strcat(format_date(d,'MMM')),'Without date')'} Code:
program: ifempty(format_date(raw_field('#mydate', ''), 'MMM'), 'Without date') 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 |
02-18-2023, 01:21 PM | #514 |
Custom User Title
Posts: 8,829
Karma: 62032371
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 |
02-18-2023, 01:32 PM | #515 | |
Guru
Posts: 733
Karma: 228142
Join Date: Sep 2017
Location: Argentina
Device: moon+ reader, kindle paperwhite
|
Quote:
Brilliant !! thank you so much !! |
|
Advert | |
|
02-18-2023, 01:58 PM | #516 | |
Grand Sorcerer
Posts: 11,778
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
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 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 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 '' |
|
02-23-2023, 05:06 PM | #517 |
Custom User Title
Posts: 8,829
Karma: 62032371
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. |
02-23-2023, 05:37 PM | #518 |
Custom User Title
Posts: 8,829
Karma: 62032371
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, ',') 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. |
02-23-2023, 05:57 PM | #519 |
Custom User Title
Posts: 8,829
Karma: 62032371
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. |
02-23-2023, 09:07 PM | #520 |
Addict
Posts: 287
Karma: 2534928
Join Date: Nov 2022
Location: Canada
Device: Kobo Aura 2
|
|
02-23-2023, 09:20 PM | #521 |
Custom User Title
Posts: 8,829
Karma: 62032371
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Yes. Silly mistake.
|
03-03-2023, 12:45 AM | #522 |
Custom User Title
Posts: 8,829
Karma: 62032371
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') Code:
'^(foo|bar)$' in $#columnname Last edited by ownedbycats; 03-03-2023 at 01:09 AM. |
03-03-2023, 05:48 AM | #523 |
Grand Sorcerer
Posts: 11,778
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
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.
|
03-12-2023, 01:09 AM | #524 |
Custom User Title
Posts: 8,829
Karma: 62032371
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, ',') 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. |
03-12-2023, 04:43 AM | #525 | |
Grand Sorcerer
Posts: 11,778
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
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, ',') |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Library Management: various questions not worth their own thread | ownedbycats | Library Management | 153 | 05-14-2024 01:30 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 |