06-04-2023, 06:52 AM | #631 | |
Grand Sorcerer
Posts: 11,951
Karma: 7225107
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Reading what you say and the code, it appears that:
This template does one version of what you might be asking for. Code:
program: tags = 'Fiction.Cultures & Regions.Canada.Western Canada, Fiction.Cultures & Regions.Metis, Fiction.Historical Fiction, Fiction.Bar.Mumble'; new_tags = ''; for t in tags: if '\.Cultures & Regions\.' in t then nt = list_item(t, -1, '.') else nt = re(t, '\.', ',') fi; new_tags = list_union(new_tags, nt, ',') rof; list_sort(new_tags, 0, ',') Code:
Bar, Fiction, Historical Fiction, Metis, Mumble, Western Canada |
|
06-04-2023, 07:14 AM | #632 | |
Custom User Title
Posts: 9,344
Karma: 63297233
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Quote:
Code:
program: if '^(Fiction|Nonfiction|Magazines & Publications)' in $#booktype then ## Remove 'Culture & Regions' items as they're processed differently split_tags = list_re_group($tags, ',', '.', '(^.*Cultures & Regions.*$)', ''); ## Split tags or return an empty split_tags = re(split_tags, '\.', ',') else split_tags = '' fi; ## Cultures & Regions - list_item with a '.' separator to get the lastmost item cultures_tags = list_re($tags, ',', 'Cultures & Regions', ''); cultures_tags = list_item(cultures_tags, -1, '.'); ## Re-merge this with split_tags split_tags = list_union(split_tags, cultures_tags, ','); ## Removing a few unwanteds and sorting cleaned_tags = list_sort(list_difference( split_tags, '[Cleanup], Fiction, Nonfiction, Magazines & Publications, Topics', ','), 0, ','); ## Add 'Omnibus' if applicable if 'omnibus' in $#admintags then cleaned_tags = 'Omnibus' & if cleaned_tags then ', ' & cleaned_tags fi fi; cleaned_tags |
|
Advert | |
|
06-11-2023, 08:37 PM | #633 |
Custom User Title
Posts: 9,344
Karma: 63297233
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
What would be the best way to remove excessive whitespaces in the middle of a value? (Calibre seems to remove them at the beginnings and endings.)
I was thinking something like re checking for two or more spaces but wasn't sure if there was a better way. Last edited by ownedbycats; 06-12-2023 at 12:30 AM. |
06-12-2023, 12:28 AM | #634 |
Custom User Title
Posts: 9,344
Karma: 63297233
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Additional question:
I have this template for listing the first letter (or 0-9 if numeric) Code:
{title_sort:'contains(t=uppercase(re($, '^\W*(\w).*$','\1')), '\d', '0-9', t)'} Last edited by ownedbycats; 06-12-2023 at 12:31 AM. |
06-12-2023, 05:37 AM | #635 | ||
Grand Sorcerer
Posts: 11,951
Karma: 7225107
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
re(val, '\s+') Quote:
Code:
{title_sort:'contains(t=transliterate(uppercase(re($, '^\W*(\w).*$','\1'))), '\d', '0-9', t)'} |
||
Advert | |
|
06-17-2023, 05:35 PM | #636 |
Member
Posts: 23
Karma: 10
Join Date: Jul 2021
Device: none
|
Hello! Does switch_if have a [pattern, value] limit? When I tried to add over 20 pairs, it started returning the first value even if it was false.
This worked (it has 20 pairs): Code:
count = raw_field('#chapters'); chapters_count = switch_if(count>=95, 95, count>=90, 90, count>=85, 85, count>=80, 80, count>=75, 75, count>=70, 70, count>=65, 65, count>=60, 60, count>=55, 55, count>=50, 50, count>=45, 45, count>=40, 40, count>=35, 35, count>=30, 30, count>=25, 25, count>=20, 20, count>=15, 15, count>=10, 10, count>=5, 5, count>=1, 1, 0); Code:
count = raw_field('#chapters'); chapters_count = switch_if(count>=100, 100, count>=95, 95, count>=90, 90, count>=85, 85, count>=80, 80, count>=75, 75, count>=70, 70, count>=65, 65, count>=60, 60, count>=55, 55, count>=50, 50, count>=45, 45, count>=40, 40, count>=35, 35, count>=30, 30, count>=25, 25, count>=20, 20, count>=15, 15, count>=10, 10, count>=5, 5, count>=1, 1, 0); |
06-17-2023, 06:14 PM | #637 |
Custom User Title
Posts: 9,344
Karma: 63297233
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
When I tested your 21-pair template with #chaptercount, it produced the correct results.
|
06-17-2023, 06:43 PM | #638 |
Member
Posts: 23
Karma: 10
Join Date: Jul 2021
Device: none
|
For some reason it doesn't work for me :/ I even updated Calibre to the newest version but it didn't help. Any idea what the problem could be?
|
06-17-2023, 07:32 PM | #639 | ||
Grand Sorcerer
Posts: 11,951
Karma: 7225107
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Quote:
Here is your template, corrected. Code:
count = raw_field('#chapters'); chapters_count = switch_if( count >=# 100, 100, count >=# 95, 95, count >=# 90, 90, count >=# 85, 85, count >=# 80, 80, count >=# 75, 75, count >=# 70, 70, count >=# 65, 65, count >=# 60, 60, count >=# 55, 55, count >=# 50, 50, count >=# 45, 45, count >=# 40, 40, count >=# 35, 35, count >=# 30, 30, count >=# 25, 25, count >=# 20, 20, count >=# 15, 15, count >=# 10, 10, count >=# 5, 5, count >=# 1, 1, 0); |
||
06-17-2023, 08:13 PM | #640 | |
Member
Posts: 23
Karma: 10
Join Date: Jul 2021
Device: none
|
Quote:
|
|
06-17-2023, 08:18 PM | #641 |
Custom User Title
Posts: 9,344
Karma: 63297233
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
I'm still curious as to why it worked as expected for me but not estherflails.
|
06-17-2023, 08:35 PM | #642 | |
Grand Sorcerer
Posts: 11,951
Karma: 7225107
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
You could make it work lexically by formatting the test value with leading zeros. Last edited by chaley; 06-17-2023 at 08:42 PM. Reason: Changed '0'-'9' to '1'-'9' because zero would work unless the value is zero padded. |
|
06-17-2023, 08:38 PM | #643 |
Grand Sorcerer
Posts: 11,951
Karma: 7225107
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
This is a consequence of the template language being untyped, or perhaps better said typed only as string. Because it doesn't know the difference between a string and a number, you must tell it what to do by using different operators.
|
07-22-2023, 11:27 AM | #644 |
Custom User Title
Posts: 9,344
Karma: 63297233
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
I have a template that produces a list of dates all formatted the same (e.g. '2020-04-16, 2023-07-10').
How do I apply format_date() to these? Last edited by ownedbycats; 07-22-2023 at 11:38 AM. |
07-22-2023, 12:05 PM | #645 | |
Grand Sorcerer
Posts: 11,951
Karma: 7225107
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
To do it after the fact, use something like this template: Code:
program: date_list = '2020-04-16, 2023-07-10'; formatted_list = ''; for date in date_list: formatted_list = list_join(', ', formatted_list, ', ', format_date(date, 'dd-MMM-yyyy'), ', ') rof; formatted_list Code:
16-Apr-2020, 10-Jul-2023 |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Library Management: various questions not worth their own thread | ownedbycats | Library Management | 156 | 07-23-2024 11:45 PM |
[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 |