View Single Post
Old 01-17-2011, 08:49 AM   #16
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
Hi Chaley
I got ambicious. Tried to modify the function code. Want to learn.

Got a weird idea that f > 0 and f < test_val should return Reading,
tried with elif since python apparently doesn't have "case"
Calibre startup time went from 1-2 seconds to several minuttes.
Did up params from to 6, changed the column def to include Reading as last parm

code:

def evaluate(self, formatter, kwargs, mi, locals, val, is_read_pct, is_read_str,
is_not_read_str, no_page_read_str, is_reading_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
elif (f > 0) and (f < test_val):
return is_reading_str
else:

return is_not_read_str
except:
pass
return no_page_read_str


No big deal, I'm just trying to learn by doing
Cheers,

EDIT: Slow down was not caused by the edit above.
The minute I removed and other column showing the % read spead was back.
Sorry.

Last edited by pchrist7; 01-17-2011 at 09:23 AM.
pchrist7 is offline   Reply With Quote