Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 12-23-2017, 10:05 PM   #1
Thorned Rose
Member
Thorned Rose began at the beginning.
 
Thorned Rose's Avatar
 
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!
Thorned Rose is offline   Reply With Quote
Old 12-24-2017, 12:33 AM   #2
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,809
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by Thorned Rose View Post
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!
Worms. Big can of.
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
theducks is offline   Reply With Quote
Advert
Old 12-24-2017, 01:10 AM   #3
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 20,575
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by theducks View Post
Worms. Big can of.
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
Typically what one does is to put limits on the size of the integer part and the number of decimals the function can handle. So for a tax refund cheque writing function, it might be '1,000,000,000,000' and '2'. In this case I would think '1,000' and '1' would probably suffice.

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.
BetterRed is offline   Reply With Quote
Old 12-24-2017, 07:56 AM   #4
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
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
The program code needs to be copied exactly, including the leading spaces.

To use this, the template is:

Code:
{series_index:'number_as_words($)'|Book |}
Or, if you want to capitalise it:

Code:
{series_index:'capitalize(number_as_words($))'|Book |}
The code is limited as it only handles integers. If the series index is not an integer, the number will be used.


@theducks: I took this as a request for use in a metadata plugboard, not a file name template.
davidfor is offline   Reply With Quote
Old 12-24-2017, 09:58 AM   #5
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,809
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by davidfor View Post
I couldn't resist.

@theducks: I took this as a request for use in a metadata plugboard, not a file name template.
Probably a good take on the request. Too many years using a simple, filename based' device
theducks is offline   Reply With Quote
Advert
Reply

Tags
integer, plugboard, series_index, templates


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Plugboard, template, and custom composite column recipes chaley Library Management 976 04-22-2024 06:29 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


All times are GMT -4. The time now is 01:42 PM.


MobileRead.com is a privately owned, operated and funded community.