![]() |
#616 | |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,870
Karma: 62040409
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Quote:
Code:
program: list_join( ', ', ## Fanfics if $publisher=='Fanfiction.net' then urls_from_identifiers('ffnet:' & select($identifiers, 'ffnet'), 0) fi, ', ', if $publisher=='Archive of Our Own' then urls_from_identifiers('ao3:' & select($identifiers, 'ao3'), 0) fi, ',', ) Last edited by ownedbycats; 05-07-2023 at 11:44 AM. |
|
![]() |
![]() |
![]() |
#617 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,798
Karma: 7029971
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
program: switch_if( $#tool == 'yenny', select($identifiers, 'yenny'), $#tool == 'Cúspide', select($identifiers, 'cuspide'), $#tool == 'Amazon', select($identifiers, 'amazon'), '') |
|
![]() |
![]() |
Advert | |
|
![]() |
#618 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,870
Karma: 62040409
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Also, a related question:
I have two identifiers, ao3 and ffnet. I'd like to change the order their links appear depending on the publisher. Here's what I have: Code:
program: list_join( ', ', ## trimmed out other lines for length switch_if( $publisher=='Archive of Our Own', urls_from_identifiers('ao3:' & select($identifiers, 'ao3'), 1), $publisher=='FanFiction.net', urls_from_identifiers('ffnet:' & select($identifiers, 'ffnet'), 1), '' ), ',', switch_if( !$publisher=='Archive of Our Own', urls_from_identifiers('ao3:' & select($identifiers, 'ao3'), 1), !$publisher=='FanFiction.net', urls_from_identifiers('ffnet:' & select($identifiers, 'ffnet'), 1), '' ), ',', ) This gets the result I want: - if both ids are available, both are listed - If publisher is Archive of Our Own, the ao3 link appears first. - If publisher is FanFiction.net, the ffnet link appears first. But is this the best way to do this? |
![]() |
![]() |
![]() |
#619 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,798
Karma: 7029971
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
program: list_join( ', ', ## trimmed out other lines for length if $publisher=='Archive of Our Own' then urls_from_identifiers('ao3:' & select($identifiers, 'ao3'), 1) fi, ', ', if !$publisher=='FanFiction.net' then urls_from_identifiers('ffnet:' & select($identifiers, 'ffnet'), 1) fi, ',', ) |
|
![]() |
![]() |
![]() |
#620 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,798
Karma: 7029971
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
|
|
![]() |
![]() |
Advert | |
|
![]() |
#621 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,798
Karma: 7029971
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
This template seems to do what you want and will be faster because only one line of one switch_if() is executed. It works by concatenating generated URLs in the order according to the publisher. If the publisher isn't one of interest then it generates 'a03' first. Missing identifiers are ignored.
Another important point: list_join() strips out empty list values, so there isn't a problem with build_url() generating a trailing comma. Code:
program: def build_url(id): return identifier_in_list($identifiers, id, urls_from_identifiers(id & ':' & select($identifiers, id), 1) & ',', '') fed; list_join( ', ', ## trimmed out other lines for length switch_if( $publisher=='Archive of Our Own', build_url('ao3') & build_url('ffnet'), $publisher=='FanFiction.net', build_url('ffnet') & build_url('ao3'), build_url('ao3') & build_url('ffnet') ), ',', ) |
![]() |
![]() |
![]() |
#622 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,870
Karma: 62040409
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Thanks
![]() |
![]() |
![]() |
![]() |
#623 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,798
Karma: 7029971
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
The solution bothered me. Reconstructing the identifier should be easier. I have submitted changes for that.
Once the changes are accepted, this template does the same thing as the previous one. The changes are in the function build_url(). If you call identifier_in_list() with two arguments then it returns the id:val pair, otherwise the empty string. You no longer need to use select() to get the identifier value. Of course, calling it with four arguments behaves as it did before. Code:
program: def build_url(id): v = identifier_in_list($identifiers, id); if v then urls_from_identifiers(v, 1) & ',' fi fed; list_join( ', ', ## trimmed out other lines for length switch_if( $publisher=='Archive of Our Own', build_url('ao3') & build_url('ffnet'), $publisher=='FanFiction.net', build_url('ffnet') & build_url('ao3'), build_url('ao3') & build_url('ffnet') ), ',', ) |
![]() |
![]() |
![]() |
#624 | |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 735
Karma: 228142
Join Date: Sep 2017
Location: Argentina
Device: moon+ reader, kindle paperwhite
|
Quote:
|
|
![]() |
![]() |
![]() |
#625 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,870
Karma: 62040409
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
I'd like to check extra_file_names for a file called 'Alternate Cover' (any extension). If it exists, add an entry to the #admintags column. Referencing the column would be faster than referencing extra_file_names for column icons and the like.
![]() Is there any improvements I can make to this? Code:
program: alternatecover = if 'Alternate Cover' inlist extra_file_names(',') then 'cover:alternate' else '' fi; list_union($#admintags, alternatecover, ',') |
![]() |
![]() |
![]() |
#626 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,798
Karma: 7029971
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
program: if has_extra_files('^Alternate Cover$') then list_union($#admintags, 'cover:alternate', ',') else $#admintags fi |
|
![]() |
![]() |
![]() |
#627 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,870
Karma: 62040409
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
I had to remove the ending anchor because the files are actually indeterminate extension and it won't match Alternate File.jpg or Alternate File.png. But it works otherwise.
![]() |
![]() |
![]() |
![]() |
#628 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,870
Karma: 62040409
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
I have a list of tags such as Fiction.Cultures & Regions.Canada and Nonfiction.Cultures & Regions.Asia.China.
I'd like to remove any tag including "Cultures & Regions" from the list before splitting it. I tried a regex list_difference but it didn't seem to work: Code:
program: list_difference($tags, '(.*)Cultures & Regions(.*)', ',');) Last edited by ownedbycats; 06-03-2023 at 05:34 PM. |
![]() |
![]() |
![]() |
#629 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,798
Karma: 7029971
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
You can do what you want with list_re_group(). This template uses that function to return a list of items not containing "Cultures & Regions" by setting that list item to the empty string. Code:
program: l = list_re_group($tags, ',', '.', '(^.*Cultures & Regions.*$)', '') |
|
![]() |
![]() |
![]() |
#630 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,870
Karma: 62040409
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Code:
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, ','); However, it only works with one item. After splitting the culture_tags list with ',', how do I process each item separately? Example: Fiction.Cultures & Regions.Canada.Western Canada, Fiction.Cultures & Regions.Metis, Fiction.Historical Fiction Preferred result (after sorting): Historical Fiction, Metis, Western Canada Actual result: Historical Fiction, Metis Last edited by ownedbycats; 06-03-2023 at 07:22 PM. |
![]() |
![]() |
![]() |
|
![]() |
||||
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 |