![]() |
#436 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,047
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Thanks
![]() New quesiton: When checking that a text column value is undefined, is there difference between !$foo and $foo == '', or any reason to prefer one or the other?? |
![]() |
![]() |
![]() |
#437 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,456
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
That said, $#foo == '' can be easier to understand, should self documentation be a goal. |
|
![]() |
![]() |
Advert | |
|
![]() |
#438 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,047
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
I made this template to check for the value of Story Does Not Exist. in one column. If it's present, then generate a new value (based on the publisher) and use list_union to merge it into #admin_tags.
Code:
program: if $#fanficerror == "Story Does Not Exist." && $publisher == 'Archive Of Our Own' then removedtags = list_item('removedfromsite:ao3',0,',') elif $#fanficerror == "Story Does Not Exist." && $publisher == 'FanFiction.net' then removedtags = list_item('removedfromsite:ffnet',0,',') fi; list_union($#admin_tags, removedtags, ',') Code:
EXCEPTION: Interpreter: Unknown identifier 'removedtags' - line number 18 EDIT: Perhaps an "else removedtags = {something}" to set it for the non-matches? But I'm not sure what to put for the something. Last edited by ownedbycats; 12-11-2022 at 12:35 AM. |
![]() |
![]() |
![]() |
#439 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,456
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
else removedtags = '' Code:
if removedtags then list_union($#admin_tags, removedtags, ',') else $#admin_tags fi Last edited by chaley; 12-11-2022 at 01:37 PM. Reason: Added missing code tags |
|
![]() |
![]() |
![]() |
#440 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,047
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Thanks. I also used an empty list for the earlier split_tags and that worked too.
![]() |
![]() |
![]() |
Advert | |
|
![]() |
#441 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,047
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Question: Here's a template I use to select, split, and sort hierarchical tags for a #subjects column:
Code:
program: ## Splitting tags if '^(Fiction|Nonfiction|Magazines & Periodicals)' in $#booktype then split_tags = re($tags, '\.', ',') else ## empty for other booktypes with more specific columns split_tags = '' fi; ## Removing a few unwanteds and sorting cleaned_tags = list_sort( list_difference( split_tags, 'Fiction, Nonfiction, Magazines & Periodicals, Cultures & Regions, Social Issues', ','), 0, ',') Fiction.Science Fiction.Space Opera Nonfiction.Biographies and Memoirs, Nonfiction.Music I thought it might make sense to change re($tags, '\.', ',') to exclude the 'topmost' (anything to the left of the first period) rather than remove them out after the fact. a) Would this improve performance? I also have other tags to remove, so I wouldn't be removing the list_difference entirely. b) What regex would I use? re($tags, '(.*)\.', ',') only semi-worked; I see why but I'm not sure how to properly capture it. ![]() Last edited by ownedbycats; 12-22-2022 at 11:53 AM. Reason: fixing the indenting on template |
![]() |
![]() |
![]() |
#442 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,456
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
For fun, here is a Python template that does what I think you want. I used #genre for both the booktype and tags values. Code:
python: def evaluate(book, context): t = book.get('#genre') # For you this would be '#booktype' # Check if any of the items in the list t startwith one of the values if any((s.startswith(('Science Fiction', 'Nonfiction', 'Magazines & Periodicals')) for s in t)): # At least one does. Split all the items into single words. # You would want the " in t " to be " in book.get('tags')" res = {t3 for t2 in t for t3 in t2.split('.')} # Remove the undesired items res -= set(('Science Fiction', 'Nonfiction', 'Magazines & Periodicals', 'Cultures & Regions', 'Social Issues')) # Sort the items then build a comma-separated string of them return ', '.join(sorted(res)) return '' Last edited by chaley; 12-24-2022 at 07:48 AM. Reason: Remove doubled "python:" in template. |
|
![]() |
![]() |
![]() |
#443 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,047
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Thanks
![]() Quick question. I modified my template to add 'Omnibus' to the beginning of the list for easier searching. Lines 3-12 and 29-30: Code:
program: ## Checking for omnibus if 'omnibus' in $#admin_tags then omnibus = 'Omnibus' else omnibus = '' fi; ## Splitting tags if '^(Fiction|Nonfiction|Magazines & Periodicals)' in $#booktype then split_tags = re($tags, '\.', ',') else split_tags = '' fi; ## Removing a few unwanteds and sorting cleaned_tags = list_sort(list_difference( split_tags, 'Fiction, Nonfiction, Magazines & Periodicals, Cultures & Regions, Social Issues', ','), 0, ','); ## Last runthrough cleaned_tags = list_union(cleaned_tags, omnibus, ',') a) Why does list_union seem to work in reverse? (e.g. if I put 'omnibus' first in template, it appears at the end of the list). b) Currently, an icon rule checks #admin_tags for 'omnibus.' Would there be any performance impact by checking the composite column instead? Thanks and merry christmas (or whatever you celebrate) ![]() Last edited by ownedbycats; 12-25-2022 at 01:50 AM. |
![]() |
![]() |
![]() |
#444 | |||
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,456
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Quote:
FWIW: Since you want Omnibus at the head of the list, I would write the template like this. Code:
program: ## Splitting tags if '^(Fiction|Nonfiction|Magazines & Periodicals)' in $#booktyoe then split_tags = re($tags, '\.', ',') else split_tags = '' fi; ## Removing a few unwanteds and sorting cleaned_tags = list_sort(list_difference( split_tags, 'Fiction, Nonfiction, Magazines & Periodicals, Cultures & Regions, Social Issues', ','), 0, ','); ## Last runthrough - Checking for omnibus if 'omnibus' in $tags then cleaned_tags = 'Omnibus' & if cleaned_tags then ', ' & cleaned_tags fi fi; cleaned_tags Quote:
|
|||
![]() |
![]() |
![]() |
#445 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,047
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Is using list_join the preferred way to de-duplicate entries?
context: https://www.mobileread.com/forums/sh...07&postcount=3 edit: I forgot list_remove_duplicates existed ![]() Last edited by ownedbycats; 12-26-2022 at 01:01 PM. |
![]() |
![]() |
![]() |
#446 |
Member
![]() Posts: 12
Karma: 10
Join Date: Oct 2017
Device: Android, Windows 10
|
I'm having some trouble with if statements in the template editor for Saving books to disk.
What I want is to handle three different cases: If the custom column "Admin tags" (admin_tags) contains "#MAS" then Code:
#MAS/{series}/{series_index:0>2s| - |}{title} ({authors}) Code:
{author_sort[0]}/{authors}/{series}/{series_index:0>2s| - |}{title} Code:
{author_sort[0]}/{authors}/{title}/{title} [export folder]/#MAS/Doctor Who New Adventures/04 - Timewyrm Revalation (Paul Cornell).epub [export folder]/C/Paul Cornell/The Severed Streets/01 - London Falling.epub [export folder]/C/Paul Cornell/Chalk/Chalk.epub (ideally the output would be as listed above, so the /C/ is from the author sort and the other outputs are from the non-sort fields, but I don't really care, if everything comes out with sort order, so it's /C/Cornell, Paul/Severed Streets, The/.... I'm also happy.) I'm trying to setup a single export job that can be picked up by another program, that needs a folder by series (or, if a book is not part of a series, a folder per book). But it has a lot of trouble with multi-author series that end up in different author folders, so I will tag those manually, so they end up in the "#MAS" folder. Looking at examples above, they seem to be written as programs. Can I put if statements in the simple template format, or I need to re-write it as a program? Thanks in advance to anyone who can advise! |
![]() |
![]() |
![]() |
#447 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,456
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Here is an example ofwhat I think you want to do: Code:
program: if '^#MAS$' inlist $#admin_tags then template('#MAS/{series}/{series_index:0>2s| - |}{title} ({authors})') elif $series then template('{author_sort[0]}/{authors}/{series}/{series_index:0>2s| - |}{title}') else template('{author_sort[0]}/{authors}/{title}/{title}') fi If you want $series and $title to use the non-sort values then change the tweak (Preferences / Tweaks) "Control formatting of title and series when used in templates (ID: save_template_title_series_sorting)". Set it to strictly_alphabetic. FWIW: You have the ' - ' in the series_index portions of the templates in the wrong place. Your examples say they should go after the second '|' so you get the index, the dash, then the title. Example: Code:
{series_index:0>2s|| - } |
|
![]() |
![]() |
![]() |
#448 | |
Member
![]() Posts: 12
Karma: 10
Join Date: Oct 2017
Device: Android, Windows 10
|
Quote:
![]() And yes, I put the ' - ' in the wrong place! Many thanks! |
|
![]() |
![]() |
![]() |
#449 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,047
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
As part of a first_non_empty, I have a if-then that checks that:
a) #kobostatus is defined b) #kobostatus is also not 'Kobo Store' c) #kobopath is undefined Code:
if $#kobostatus && !'Kobo Store' in $#kobostatus && !$#kobopath then 'snippets.png' fi EDIT: Additional question: Code:
program: days_between(format_date(today(), 'yyyy-MM-dd'), $#fanficupdated); days_between(today(), $#fanficupdated); Last edited by ownedbycats; 01-03-2023 at 10:35 PM. |
![]() |
![]() |
![]() |
#450 | ||
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,456
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
$#kobostatus != 'Kobo Store' Quote:
If both are complete times (date, time, timezone) then the difference in the time of day will figure in the date arithmetic. |
||
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Library Management: various questions not worth their own thread | ownedbycats | Library Management | 225 | 08-04-2025 06:31 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 |