![]() |
#1 |
Member
![]() Posts: 13
Karma: 10
Join Date: Dec 2017
Location: New Zealand
Device: Kobo Aura H2O2 (H2O v2)
|
Plugboard template series_index integer output as text
I am wanting to output titles as something like "Book Title (Series Title Book One)" e.g. "A Hat Full of Sky (Tiffany Aching Book Two)"
I've gotten as far as {title}{#series:| (| }{#series_index:|Book |)} but I want the series_index number to be output as a word e.g one, five, eleven, etc. I found this but I'm fairly new to Calibre's advanced stuff so I can't for the life of me work out how to implement it: https://stackoverflow.com/a/32640407 TIA! ![]() |
![]() |
![]() |
![]() |
#2 | |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,883
Karma: 59840450
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
You are going to slam into filename length limits, way faster . what happens with higher number series (volume #)? one-hundred-twenty-seven some while back, I saw the code to write out the amount on a chech from the numeric value. it was a few dozen lines as it had to parse numbers like seventeen and not as one seven. It needs to put dashes and 'and' in the proper place. Not simple ![]() |
|
![]() |
![]() |
![]() |
#3 | |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 21,603
Karma: 29709834
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
Quote:
Just for fun, here's some vaguely relevant Word macros from someone you or DoctorOhh might even know ==>> Spell Out Currency @Thorned Rose - I suspect one of the programmers can chime with a solution, after the holiday - probably written in python encapsulated in a calibre template - way beyond my tired old brain's pay grade. BR ![]() Last edited by BetterRed; 12-24-2017 at 01:22 AM. |
|
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 24,905
Karma: 47303824
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
I couldn't resist.
As the Python code was supplied, I used it to create a Template function. This is created on the Template function page of the preferences. The values are: Function: number_as_words Argument count: 1 Documentation: number_as_words(val) -- Given a number, return the words for the number. Program code: Code:
def evaluate(self, formatter, kwargs, mi, locals, val): try: num=int(val) except: return val d = { 0 : 'zero', 1 : 'one', 2 : 'two', 3 : 'three', 4 : 'four', 5 : 'five', 6 : 'six', 7 : 'seven', 8 : 'eight', 9 : 'nine', 10 : 'ten', 11 : 'eleven', 12 : 'twelve', 13 : 'thirteen', 14 : 'fourteen', 15 : 'fifteen', 16 : 'sixteen', 17 : 'seventeen', 18 : 'eighteen', 19 : 'nineteen', 20 : 'twenty', 30 : 'thirty', 40 : 'forty', 50 : 'fifty', 60 : 'sixty', 70 : 'seventy', 80 : 'eighty', 90 : 'ninety' } k = 1000 m = k * 1000 b = m * 1000 t = b * 1000 if (num < 20): return d[num] if (num < 100): if num % 10 == 0: return d[num] else: return d[num // 10 * 10] + '-' + d[num % 10] if (num < k): if num % 100 == 0: return d[num // 100] + ' hundred' else: return d[num // 100] + ' hundred and ' + int_to_en(num % 100) if (num < m): if num % k == 0: return int_to_en(num // k) + ' thousand' else: return int_to_en(num // k) + ' thousand, ' + int_to_en(num % k) if (num < b): if (num % m) == 0: return int_to_en(num // m) + ' million' else: return int_to_en(num // m) + ' million, ' + int_to_en(num % m) if (num < t): if (num % b) == 0: return int_to_en(num // b) + ' billion' else: return int_to_en(num // b) + ' billion, ' + int_to_en(num % b) if (num % t == 0): return int_to_en(num // t) + ' trillion' else: return int_to_en(num // t) + ' trillion, ' + int_to_en(num % t) return val To use this, the template is: Code:
{series_index:'number_as_words($)'|Book |} Code:
{series_index:'capitalize(number_as_words($))'|Book |} @theducks: I took this as a request for use in a metadata plugboard, not a file name template. |
![]() |
![]() |
![]() |
#5 |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,883
Karma: 59840450
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
|
![]() |
![]() |
![]() |
Tags |
integer, plugboard, series_index, templates |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Plugboard, template, and custom composite column recipes | chaley | Library Management | 1047 | 04-24-2025 10:28 PM |
Glowlight Plus plugboard/save template | charles_cinci | Devices | 5 | 12-28-2015 01:40 PM |
PLUGBOARD TEMPLATE ERROR with Sony T3 | AlexBell | Library Management | 15 | 10-29-2015 05:46 AM |
Kindle Paperwhite: Author not getting rewritten when using plugboard template | kevbo | Library Management | 5 | 09-09-2015 08:29 PM |
Plugboard, template series_index first? | Truthowl | Library Management | 6 | 09-13-2014 12:34 PM |