Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 01-17-2011, 03:27 PM   #31
gweminence
Fat Guy
gweminence can name that song in three notesgweminence can name that song in three notesgweminence can name that song in three notesgweminence can name that song in three notesgweminence can name that song in three notesgweminence can name that song in three notesgweminence can name that song in three notesgweminence can name that song in three notesgweminence can name that song in three notesgweminence can name that song in three notesgweminence can name that song in three notes
 
Posts: 395
Karma: 24165
Join Date: Jun 2010
Device: Kindle 3
Ah, yeah that worked well. Thanks once again.

Bummer about the 'nope', though.
gweminence is offline   Reply With Quote
Old 01-17-2011, 04:15 PM   #32
beckywc
Addict
beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.
 
beckywc's Avatar
 
Posts: 270
Karma: 1050426
Join Date: Feb 2010
Location: California
Device: iPad Mini w/Retina, Kindle 3, Kindle Fire HDX 8.9, & Asus Transformer
Quote:
Originally Posted by chaley View Post
As long as I am commenting.

Code:
		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
The line you added could be
Code:
		elif f > 0:
			return is_reading_str
		else:
because the if above has already removed all the cases that the clause after the 'and' would catch.
Trying to add Reading but keep getting an error after else. This is what I have thus far:

Spoiler:
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:
return is_reading_str
else:
return is_not_read_str
except:
pass
return no_page_read_str


I know it is something I'm doing wrong your help would be greatly appreciated.
beckywc is offline   Reply With Quote
Old 01-17-2011, 04:51 PM   #33
bristolman
Junior Member
bristolman began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Dec 2010
Device: kindle 2
me too . iwas able to create a column and a yes /no for read (doesnt seem to work real well getting the ye no box to pop up) . where/how do you ( using calibre .40 )put the comment{comments:kindle_read_percent(95,Yes,No,Uno pened)}? this is where im confused.
bristolman is offline   Reply With Quote
Old 01-17-2011, 05:50 PM   #34
chaley
"chaley", not "charley"
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: 5,797
Karma: 1212788
Join Date: Jan 2010
Location: France
Device: Many android devices
Thumbs up

Quote:
Originally Posted by beckywc View Post
Trying to add Reading but keep getting an error after else. This is what I have thus far:

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:
			return is_reading_str
		else:
			return is_not_read_str
	except:
		pass
	return no_page_read_str
I know it is something I'm doing wrong your help would be greatly appreciated.
Use the source from the above code block. I fixed the indents on the else and the return.

When doing python functions, spacing and indenting is critical. You must get it exactly right. Copying and pasting code from other than code blocks is almost certain to get it wrong.
chaley is offline   Reply With Quote
Old 01-17-2011, 05:51 PM   #35
chaley
"chaley", not "charley"
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: 5,797
Karma: 1212788
Join Date: Jan 2010
Location: France
Device: Many android devices
Quote:
Originally Posted by bristolman View Post
where/how do you ( using calibre .40 )put the comment{comments:kindle_read_percent(95,Yes,No,Uno pened)}? this is where im confused.
As said in post #2, you must create a custom column 'based on other columns'. The template goes there.
chaley is offline   Reply With Quote
Old 01-19-2011, 05:19 AM   #36
beckywc
Addict
beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.
 
beckywc's Avatar
 
Posts: 270
Karma: 1050426
Join Date: Feb 2010
Location: California
Device: iPad Mini w/Retina, Kindle 3, Kindle Fire HDX 8.9, & Asus Transformer
Quote:
Originally Posted by pchrist7 View Post
Hi All
Hope some of you can tell whether this is possible or not.
If yes, then please point me in the right directions.
Have a Kindle 3, I always fetch annotations when using Calibre.
what I'm interested in, is if a book is read or not.
The annotations will append something like:

10-12-2010
Last Page Read: Location 4862 (99%)

to each books comments, if it has been opened on the Kindle.

IS it possible to create a new column, which searches the "Comments" for
"Last Page Read: Location " and then grab the 99% to put into my custom column
Chaley,

I would like to pick up the date from the annotations and put in a custom column Last Read: 10-12-2010. I have Calibre v. 7.40.

How would I do this using a template. Thanks.
beckywc is offline   Reply With Quote
Old 01-19-2011, 05:58 AM   #37
chaley
"chaley", not "charley"
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: 5,797
Karma: 1212788
Join Date: Jan 2010
Location: France
Device: Many android devices
Try
Code:
{comments:'contains($, 'Last Page Read:', re($, '(?is).*(\d\d-\d\d-\d\d\d\d).*?Last Page Read:.*', '\1'), 'Nope')'}
Change the 'Nope' to whatever you want.
chaley is offline   Reply With Quote
Old 01-19-2011, 07:39 AM   #38
beckywc
Addict
beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.
 
beckywc's Avatar
 
Posts: 270
Karma: 1050426
Join Date: Feb 2010
Location: California
Device: iPad Mini w/Retina, Kindle 3, Kindle Fire HDX 8.9, & Asus Transformer
Do I place this in the documentation box of the template function? Sorry I'm really a new at this.
beckywc is offline   Reply With Quote
Old 01-19-2011, 07:47 AM   #39
chaley
"chaley", not "charley"
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: 5,797
Karma: 1212788
Join Date: Jan 2010
Location: France
Device: Many android devices
Quote:
Originally Posted by beckywc View Post
Do I place this in the documentation box of the template function? Sorry I'm really a new at this.
No. This is a template, and it goes in the template box when you create the new custom column.

In general, templates begin with a { character or, rarely, the word 'program:'. Python code, the stuff that goes into the template functions dialog, begin with 'def evaluate'. It will be rare that someone provides a python template function, because so few people can understand and modify them. Templates are more easily modified by users, so you will see them more often.

Pointer: you can edit a composite (column made from columns) custom column's template by clicking in the column and hitting F2. A dialog box will open in which you can change the template. This is far more convenient than editing the column definition.

You might want to read calibre's template language manual http://calibre-ebook.com/user_manual/template_lang.html. That might give you some info about what it is the template is doing.
chaley is offline   Reply With Quote
Old 01-19-2011, 08:10 AM   #40
beckywc
Addict
beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.
 
beckywc's Avatar
 
Posts: 270
Karma: 1050426
Join Date: Feb 2010
Location: California
Device: iPad Mini w/Retina, Kindle 3, Kindle Fire HDX 8.9, & Asus Transformer
Quote:
Originally Posted by chaley View Post
Try
Code:
{comments:'contains($, 'Last Page Read:', re($, '(?is).*(\d\d-\d\d-\d\d\d\d).*?Last Page Read:.*', '\1'), 'Nope')'}
Change the 'Nope' to whatever you want.
I placed this in the custom column and all of the comments section including the annotation was placed in the column. I was wanting just the date the book was read. Did I do something wrong?

Last edited by beckywc; 01-19-2011 at 08:12 AM.
beckywc is offline   Reply With Quote
Old 01-19-2011, 08:14 AM   #41
chaley
"chaley", not "charley"
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: 5,797
Karma: 1212788
Join Date: Jan 2010
Location: France
Device: Many android devices
Quote:
Originally Posted by beckywc View Post
I placed this in the custom column and all of the comments section including the annotation was placed in the column. Did I do something wrong?
Please copy exactly what you put into the template and post it here. It would be helpful if you put it in a 'CODE' block, which you get by clicking on the '#' character on the toolbar in the reply window.

Also copy one of the comments containing an annotation and post that. I don't have a kindle so I cannot see what it is you are dealing with.
chaley is offline   Reply With Quote
Old 01-19-2011, 08:24 AM   #42
beckywc
Addict
beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.
 
beckywc's Avatar
 
Posts: 270
Karma: 1050426
Join Date: Feb 2010
Location: California
Device: iPad Mini w/Retina, Kindle 3, Kindle Fire HDX 8.9, & Asus Transformer
Quote:
Originally Posted by chaley View Post
Please copy exactly what you put into the template and post it here. It would be helpful if you put it in a 'CODE' block, which you get by clicking on the '#' character on the toolbar in the reply window.

Also copy one of the comments containing an annotation and post that. I don't have a kindle so I cannot see what it is you are dealing with.
This is what I placed in the template field:

{comments:'contains($, 'Last Page Read:', re($, '(?is).*(\d\d-\d\d-\d\d\d\d).*?Last Page Read:.*', '\1'), 'Not Read')'}

And this is one of my comments contains:

SUMMARY:

A homely woman who fears she will never marry becomes a mail-order bride. The man she comes for rejects her but another offers her marriage. She accepts, not believing love will result from the union. Love, after all, is for beautiful women. Isn't it?

9/27/2010
Last Page Read: Location 4411 (99%)

Thanks
beckywc is offline   Reply With Quote
Old 01-19-2011, 08:28 AM   #43
chaley
"chaley", not "charley"
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: 5,797
Karma: 1212788
Join Date: Jan 2010
Location: France
Device: Many android devices
The problem is that your first example uses '-' as the separator in the date, but the last example uses '/'. I didn't know that the slash format was possible, so didn't account for it.

Change the template to
Code:
{comments:'contains($, 'Last Page Read:', re($, '(?is).*(\d\d[-/]\d\d[-/]\d\d\d\d).*?Last Page Read:.*', '\1'), 'Not Read')'}
chaley is offline   Reply With Quote
Old 01-19-2011, 08:43 AM   #44
beckywc
Addict
beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.
 
beckywc's Avatar
 
Posts: 270
Karma: 1050426
Join Date: Feb 2010
Location: California
Device: iPad Mini w/Retina, Kindle 3, Kindle Fire HDX 8.9, & Asus Transformer
Quote:
Originally Posted by chaley View Post
The problem is that your first example uses '-' as the separator in the date, but the last example uses '/'. I didn't know that the slash format was possible, so didn't account for it.

Change the template to
Code:
{comments:'contains($, 'Last Page Read:', re($, '(?is).*(\d\d[-/]\d\d[-/]\d\d\d\d).*?Last Page Read:.*', '\1'), 'Not Read')'}
Quick question some in the custom column presented the date others stayed them same. Do you know why? Here is an example of the comment field that didn't change:

When Dr. Whitney himself is murdered, Ryland has only one person left to trust: the beautiful Lily. Possessed of an uncanny sixth sense herself, Lily shares Ryland's every new fear, every betrayal, every growing suspicion, and every passionate beat of the heart. Together, they will be drawn deeper into the labyrinth of her father's past…and closer to a secret that someone would kill to keep hidden.

1/18/2011
Last Page Read: Location 5507 (99%)

This one the date didn't show it still contains the comments and the annotation in the field.

It's weird that some changed to just the date and some still has everything.
beckywc is offline   Reply With Quote
Old 01-19-2011, 08:56 AM   #45
chaley
"chaley", not "charley"
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: 5,797
Karma: 1212788
Join Date: Jan 2010
Location: France
Device: Many android devices
Quote:
Originally Posted by beckywc View Post
1/18/2011
Last Page Read: Location 5507 (99%)

This one the date didn't show it still contains the comments and the annotation in the field.

It's weird that some changed to just the date and some still has everything.
This is yet another example of a different date format. For this one, the month is only one character instead of 2. Again, I didn't know this could happen, so the template didn't take it into account.

Try:
Code:
{comments:'contains($, 'Last Page Read:', re($, '(?is).*\s(\d+[-/]\d+[-/]\d\d\d\d).*?Last Page Read:.*', '\1'), 'Not Read')'}
Are there any more variations that must be accounted for?
chaley is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
"integrity error column book is not unique" Atiajar Calibre 4 12-22-2010 12:22 AM
Can Comments be "saved to disk" for reading? sailingpeanut Recipes 1 10-10-2010 11:06 AM
(2 books) in "On Device" column Sony Reader phenomshel Calibre 23 09-19-2010 06:43 PM
Bug? "Insert metadata as page at start of book" doesnt encode Comments field properly rollercoaster Calibre 2 04-24-2010 11:40 PM


All times are GMT -4. The time now is 02:36 AM.


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