10-23-2024, 11:41 AM | #151 |
Grand Sorcerer
Posts: 12,032
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
|
10-23-2024, 12:48 PM | #152 | |
Grand Sorcerer
Posts: 12,032
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Another example: Code:
program: if '^science' inlist_field '#genre' then 'yes' else 'no' fi |
|
10-23-2024, 12:58 PM | #153 |
Custom User Title
Posts: 9,563
Karma: 64960981
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Ah, I was looking in the function reference. It works when I tried it.
|
10-23-2024, 01:08 PM | #154 |
Custom User Title
Posts: 9,563
Karma: 64960981
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Does inlist_field only work for strings? e.g.:
Code:
program: readgoal = strcat('readinggoal:', format_date(today(), 'yyyy')); if readgoal inlist_field '#admintags' |
10-23-2024, 01:12 PM | #155 | |
Grand Sorcerer
Posts: 12,032
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
EDIT 2: the changes to the syntax highlighter are now in calibre source. Last edited by chaley; 10-23-2024 at 06:46 PM. Reason: Removed edit 1 -- identifiers now works in the same way as inlist |
|
10-28-2024, 12:02 PM | #156 |
Grand Sorcerer
Posts: 12,032
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
28 Oct 2024 (in calibre source)
|
10-28-2024, 02:06 PM | #157 |
Wizard
Posts: 1,088
Karma: 1221485
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
|
Nice. Even simpler. Now I can find all authors without a note like this:
Code:
not template:"""program: if $authors in has_note('authors', '') then '1' else '' fi;#@#:t:1""" |
10-28-2024, 04:11 PM | #158 | |
Grand Sorcerer
Posts: 12,032
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
It will also be at least 10 times slower than the template I posted in the other thread. Perhaps as much as 50 times slower. Of course, this only matters if you have lots of books. This template uses the new has_note() to find books where 1 or more authors don't have a note. It works by returning '1' if all authors for a book have notes, otherwise ''. It will be slightly faster than your template, but nowhere near as fast as the python template. Code:
program: if list_count(has_note('authors', ''), '&') ==# list_count_field('authors') then return '1' fi; '' |
|
10-28-2024, 04:24 PM | #159 |
Wizard
Posts: 1,088
Karma: 1221485
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
|
Oh, I see my mistake now. I'll leave the python template, then.
When using my template, I do think the first time was slow, then other times were fast. I guess it's the work of the cache in action. ________________________ EDIT: I decided to check the difference between the two templates (mine and yours, but not the python one). It seems to find the same results, even if only one author has a note. Then, looking again at the code, I notice it does work: Example: If i have a book with two authors (AuthorA and AuthorB), and only have notes for AuthorA. $authors = 'AuthorA & AuthorB' has_note('authors', '') = 'AuthorA' Now, the comparison if $authors in has_note('authors', '') will return False, as intended. But I'm definitely staying with the python template. Last edited by thiago.eec; 10-28-2024 at 05:11 PM. |
|
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 |
Template Language | phossler | Calibre | 8 | 01-12-2016 05:37 PM |
Help needed with template language | Mamaijee | Devices | 12 | 02-19-2013 02:52 AM |
Help with template language | Pepin33 | Calibre | 8 | 11-11-2012 09:32 AM |
Template language question | BookJunkieLI | Library Management | 7 | 02-02-2012 07:55 PM |