Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 11-10-2012, 05:25 AM   #1
Pepin33
Zealot
Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.
 
Posts: 109
Karma: 419
Join Date: Aug 2012
Location: Spain
Device: Kindle Touch
Red face Help with template language

I'm trying to make a saving template in Calibre. I want to get an identifier from my books and format it to remove left zeros.

For example, if identifier in a book is 0000123, I want my book be saved as "123".
Identifiers are always 8 digit numbers, filled with zeros (00000001, 0000002, etc).

I'm trying to use this template: {identifiers:select(my_id):G}, but I get an error saying "my_id" is not a number, but a string.

I was looking at templates languages, but I can't find any function to convert a string to an integer. Anybody can help me?

Last edited by Pepin33; 11-10-2012 at 05:36 AM.
Pepin33 is offline   Reply With Quote
Old 11-10-2012, 10:18 AM   #2
theducks
Grand Sorcerer
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: 14,707
Karma: 5643657
Join Date: Aug 2009
Location: (The original) Silicon Valley, USA
Device: Galaxy Tab 2, Astak Pocket Pro, K4NT
Quote:
Originally Posted by Pepin33 View Post
I'm trying to make a saving template in Calibre. I want to get an identifier from my books and format it to remove left zeros.

For example, if identifier in a book is 0000123, I want my book be saved as "123".
Identifiers are always 8 digit numbers, filled with zeros (00000001, 0000002, etc).

I'm trying to use this template: {identifiers:select(my_id):G}, but I get an error saying "my_id" is not a number, but a string.

I was looking at templates languages, but I can't find any function to convert a string to an integer. Anybody can help me?
I am no way a power user of the template language...But

Identifiers: usually consists of 2 parts (the colon is the separator)
1) whose: amazon:
2) the string

Maybe you want: identifier_in_list(val, id, found_val, not_found_val)
theducks is offline   Reply With Quote
Old 11-10-2012, 11:37 AM   #3
Pepin33
Zealot
Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.
 
Posts: 109
Karma: 419
Join Date: Aug 2012
Location: Spain
Device: Kindle Touch
Quote:
Originally Posted by theducks View Post
Identifiers: usually consists of 2 parts (the colon is the separator)
1) whose: amazon:
2) the string
Yes, you're right. That is. But my books have a "custom" identifier to identify every one. And the value for this identifier was generated as {'my_id:':'%08d'%book_id}.

Now, I want to save those books using the identifier, but I want to remove left zeros. And if you're thinking about using book_id instead of my_id, not, that doesn't work, because the books are translated to another library so now my_id is not the same as the book_id...
Pepin33 is offline   Reply With Quote
Old 11-10-2012, 11:46 AM   #4
theducks
Grand Sorcerer
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: 14,707
Karma: 5643657
Join Date: Aug 2009
Location: (The original) Silicon Valley, USA
Device: Galaxy Tab 2, Astak Pocket Pro, K4NT
Quote:
Originally Posted by Pepin33 View Post
Yes, you're right. That is. But my books have a "custom" identifier to identify every one. And the value for this identifier was generated as {'my_id:':'%08d'%book_id}.

Now, I want to save those books using the identifier, but I want to remove left zeros. And if you're thinking about using book_id instead of my_id, not, that doesn't work, because the books are translated to another library so now my_id is not the same as the book_id...
Off the top of my head
use Nested commands (program mode),:
convert the numeric string portion to a (integer)Number, then convert that back to a string. That should lose the leading zeros.
theducks is offline   Reply With Quote
Old 11-10-2012, 02:28 PM   #5
Pepin33
Zealot
Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.
 
Posts: 109
Karma: 419
Join Date: Aug 2012
Location: Spain
Device: Kindle Touch
Quote:
Originally Posted by theducks View Post
Off the top of my head
use Nested commands (program mode),:
convert the numeric string portion to a (integer)Number, then convert that back to a string. That should lose the leading zeros.
Yes, but how to do that is what I'm asking for.

I tried with:
program: str(int(template('[[identifiers:select(my_id)]]')))

But this doesn't work, and I can't find any function in template language to convert a string to an integer....
Pepin33 is offline   Reply With Quote
Old 11-11-2012, 04:52 AM   #6
chaley
"chaley", not "charley"
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 5,520
Karma: 855450
Join Date: Jan 2010
Location: France
Device: Many android devices
Take a look at the format_number function.
chaley is offline   Reply With Quote
Old 11-11-2012, 07:21 AM   #7
Pepin33
Zealot
Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.
 
Posts: 109
Karma: 419
Join Date: Aug 2012
Location: Spain
Device: Kindle Touch
Smile

Quote:
Originally Posted by chaley View Post
Take a look at the format_number function.
¡Yes! ¡That was the answer! Works perfectly with:
Code:
program:format_number(template('[[identifiers:select(my_id)]]'), '{0:g}')
Thank you very much, chaley (and also theducks).
Pepin33 is offline   Reply With Quote
Old 11-11-2012, 08:14 AM   #8
chaley
"chaley", not "charley"
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 5,520
Karma: 855450
Join Date: Jan 2010
Location: France
Device: Many android devices
Quote:
Originally Posted by Pepin33 View Post
¡Yes! ¡That was the answer! Works perfectly with:
Code:
program:format_number(template('[[identifiers:select(my_id)]]'), '{0:g}')
Thank you very much, chaley (and also theducks).
The following template will have better performance, something that might matter if you have thousands of books in your library.
Code:
program:format_number(select(field('identifiers'), 'my_id'), '{0:d}')
chaley is offline   Reply With Quote
Old 11-11-2012, 08:32 AM   #9
Pepin33
Zealot
Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.Pepin33 has a complete set of Star Wars action figures.
 
Posts: 109
Karma: 419
Join Date: Aug 2012
Location: Spain
Device: Kindle Touch
Quote:
Originally Posted by chaley View Post
The following template will have better performance, something that might matter if you have thousands of books in your library.
Code:
program:format_number(select(field('identifiers'), 'my_id'), '{0:d}')
Ok, thanks again for your help, chaley.
Pepin33 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with template KALKITO Library Management 1 07-02-2012 02:54 PM
Template language question BookJunkieLI Library Management 7 02-02-2012 06:55 PM
v8.4 template error cybmole Calibre 5 06-04-2011 11:10 AM
Stupid question about calibre language template Cammagno Calibre 1 01-08-2011 08:00 AM
page-template ? setzer Calibre 13 07-27-2009 11:23 PM


All times are GMT -4. The time now is 12:58 AM.


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