View Single Post
Old 01-22-2011, 02:11 AM   #57
pchrist7
Addict
pchrist7 is kind to children and small, furry animalspchrist7 is kind to children and small, furry animalspchrist7 is kind to children and small, furry animalspchrist7 is kind to children and small, furry animalspchrist7 is kind to children and small, furry animalspchrist7 is kind to children and small, furry animalspchrist7 is kind to children and small, furry animalspchrist7 is kind to children and small, furry animalspchrist7 is kind to children and small, furry animalspchrist7 is kind to children and small, furry animalspchrist7 is kind to children and small, furry animals
 
pchrist7's Avatar
 
Posts: 385
Karma: 6514
Join Date: Aug 2010
Location: Denmark
Device: Kindle 3 3G+Wifi, Oasis
Thanks !

Quote:
Originally Posted by chaley View Post
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.
Hi Chaley
Thanks a lot. You probably saved a lot testing hours, trying to grab the date.
Will test a bit later today when I'm home from work.
pchrist7 is offline   Reply With Quote