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 10-15-2013, 09:26 AM   #16
kcz
Member
kcz began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Oct 2013
Device: Kindle
Quote:
Originally Posted by chaley View Post
I decided to give it a try because I need more experience with the new calibre db layer.

Here is a standalone python program built on calibre's db layer that does what I think you want. It fills in a custom text column with the proper format for a series, computed by looking at all the books in the series.
Thanks, I solved it a few days ago by creating a customized column which holds a formatting template. (e.g. 9.99 will output a 2 as 2.00, 99.99 will output a 2.5 as 02.50, 999 will output 2 as 002)

Right now I populate this column manually, but I will either write a script or a plugin to do that for me. Just not sure when I will find the time to do so.
I have a concept, but I will have to look into plugin development in more detail.
If you are interested, here is my format_index function:

Code:
def evaluate(self, formatter, kwargs, mi, locals, val, template):
	# Check if the argument is empty. If so, return the empty string
	if val == '':
		return ''
	# Return the input as is, if template is empty
	if template == '':
		return val
	# Not empty. Must be a number. If it isn't, bad things will happen.
	# split the strings in integer and fractional parts
	v = val.split('.')
	t = template.split('.')
	if len(v) == 1:
		v.extend('0')
	
	# trim leading and trailing zeros
	v_int = v[0].lstrip( '0' )
	if len(t) != 1:
		v_frac = v[1].rstrip( '0' )

	# determine the number of digits for the integer and fractional part of the template
	digits_int = len(t[0].lstrip('0'))
	if len(t) != 1:
		digits_frac = len(t[1].rstrip('0'))
	
	# pad the input val according to the template
	val_int = v_int.rjust(digits_int, '0')
	if len(t) != 1 and digits_frac != 0:
		val_frac = v_frac.ljust(digits_frac, '0')
		retval = val_int + '.' + val_frac
	else:
		retval = val_int

	return retval
I call it like this:

Code:
program: format_index(field('series_index'), field('#seriestemplate'))
kcz is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Customize series_index value luoman Calibre 3 08-23-2013 04:11 AM
dynamic content manipulation maze ePub 1 02-15-2013 11:01 PM
[Kindle Touch] LocalStorage manipulation tommytomtom Kindle Developer's Corner 1 05-12-2012 11:16 AM
PDF annotation and manipulation? mr_ed enTourage eDGe 10 06-27-2011 05:23 PM
Section for content manipulation and issues? POLL Alexander Turcic iRex 3 09-14-2006 04:43 AM


All times are GMT -4. The time now is 05:29 PM.


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