|
|
#511 |
|
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 922
Karma: 810834
Join Date: Sep 2017
Location: Buenos Aires, 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 |
|
|
|
|
|
#512 | |
|
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 922
Karma: 810834
Join Date: Sep 2017
Location: Buenos Aires, Argentina
Device: moon+ reader, kindle paperwhite
|
Quote:
The month must be capital letter (MMM) but I did not discover why I get Bad Date |
|
|
|
|
|
|
#513 |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
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 02:59 PM. Reason: Grammar |
|
|
|
|
|
#514 |
|
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,360
Karma: 79528341
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 |
|
|
|
|
|
#515 | |
|
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 922
Karma: 810834
Join Date: Sep 2017
Location: Buenos Aires, Argentina
Device: moon+ reader, kindle paperwhite
|
Quote:
Brilliant !! thank you so much !! |
|
|
|
|
|
|
#516 | |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
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 ''
|
|
|
|
|
|
|
#517 |
|
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,360
Karma: 79528341
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 06:09 PM. |
|
|
|
|
|
#518 |
|
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,360
Karma: 79528341
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 07:39 PM. |
|
|
|
|
|
#519 |
|
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,360
Karma: 79528341
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. |
|
|
|
|
|
#520 |
|
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 295
Karma: 2534928
Join Date: Nov 2022
Location: Canada
Device: Kobo Aura 2
|
|
|
|
|
|
|
#521 |
|
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,360
Karma: 79528341
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Yes. Silly mistake.
|
|
|
|
|
|
#522 |
|
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,360
Karma: 79528341
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 02:09 AM. |
|
|
|
|
|
#523 |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
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.
|
|
|
|
|
|
#524 |
|
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,360
Karma: 79528341
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 04:15 AM. |
|
|
|
|
|
#525 | |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
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, ',') |
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Library Management: various questions not worth their own thread | ownedbycats | Library Management | 253 | 10-21-2025 09:15 AM |
| [Metadata Source Plugin] Questions regarding parse select, docs and ref templates | Boilerplate4U | Development | 13 | 07-07-2020 03:35 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 | Amazon Fire | 7 | 05-10-2013 10:19 PM |
| Thread management questions | meme | Feedback | 6 | 01-31-2011 06:07 PM |