View Single Post
Old 01-21-2011, 11:26 AM   #56
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: 12,471
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by pchrist7 View Post
Hi beckywc
Got it.
wonder if it can be done.
Will give it a try or two during the weekend.
You can do it.

Try playing with some variant of this
Code:
def evaluate(self, formatter, kwargs, mi, locals, val, is_read_pct, is_read_str, 
				is_reading_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('\s(\d+[-/]\d+[-/]\d\d\d\d).*?Last Page Read: location \d+ \((\d+)%\)', val, re.I + re.DOTALL);
	if mg is None:
		return no_page_read_str
	date = mg.group(1)
	pct = mg.group(2)
	try:
		f = int(pct)
		if f >= test_val:
			return date
		return is_reading_str + ': ' + pct + '%'
	except:
		pass
	return no_page_read_str
I haven't tried it, so it might not compile. Should be close.

I changed the regexp in the re(...) clause to carve out both the date and the percent. If it finds them, then the ifs below choose what to return.

Have fun.
chaley is offline   Reply With Quote