View Single Post
Old 01-17-2011, 05:46 AM   #14
chaley
Grand Sorcerer
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: 11,733
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
If you are willing to experiment... Below find a template function that does what you want. It should be orders of magnitude faster than the template program.

You must be running 0.7.40 or newer to use this.

To set it up:
1) go to preferences -> advanced -> template functions.
2) in the Function box type: kindle_read_percent
3) in the arg count box type: 5
4) in the documentation box, paste the following:
Code:
Check if the associated field contains a kindle annotation for percent read. If not, return no_page_read_str. If so, then compare that percent against is_read_pct. If the val is equal or larger, then return is_read_str, otherwise return is_not_read_str.

One usage: {comments:kindle_read_percent(95,Yes,No,Unopened)}
5) In the program code box, paste the following:
Code:
def evaluate(self, formatter, kwargs, mi, locals, val, is_read_pct, is_read_str, 
				is_not_read_str, no_page_read_str):
	try:
		test_val = int(is_read_pct)
	except:
		return 'is_read_pct is not a number'

	import re
	mg = re.match('.*last page read: location \d+ \((\d+)%\)', val, re.I + re.DOTALL);
	if mg is None:
		return no_page_read_str
	try:
		f = int(mg.group(1))
		if f >= test_val:
			return is_read_str
		return is_not_read_str
	except:
		pass
	return no_page_read_str
6) press the Create button, then the Apply button, then the Close button.
7) put into your custom column:
Code:
{comments:kindle_read_percent(95,Yes,No,Unopened)}
You can change the strings and percent, but try it once this way to be sure that it works.
chaley is offline   Reply With Quote