Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 04-27-2023, 11:37 AM   #946
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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Template search: find books with extra data files

Starting with calibre 6.17:

This template search will find books that have any extra files in the book's data/ folder:
Code:
template:"""program:has_extra_files()#@#:b:yes"""
chaley is offline   Reply With Quote
Old 04-30-2023, 08:45 AM   #947
Amon_Re
Zealot
Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.
 
Posts: 132
Karma: 14644
Join Date: Sep 2015
Device: Kobo Elipsa, Poketbook Inkpad 3 & Boyue Likebook Minas
I'm trying to make a composite column to display the "Reading Status" based on the actual value of a column "%percent read".

I can use the following to set to 'Complete' if %percent read" is set to 100
Code:
{:'cmp(field('#kobo_percent_read'),100,'','Finished','Finished')'}
I want to change this to set to reading if the value is between 1 and 99 and unread if 0 or blank

Can this be done?
Amon_Re is offline   Reply With Quote
Advert
Old 04-30-2023, 10:24 AM   #948
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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Amon_Re View Post
I'm trying to make a composite column to display the "Reading Status" based on the actual value of a column "%percent read".

I can use the following to set to 'Complete' if %percent read" is set to 100
Code:
{:'cmp(field('#kobo_percent_read'),100,'','Finished','Finished')'}
I want to change this to set to reading if the value is between 1 and 99 and unread if 0 or blank

Can this be done?
Assuming you are running calibre 6.12 or later:
Code:
{#kobo_percent_read:'switch_if($ >= 100, 'finished', $ <= 0, 'unread', 'reading')'}
chaley is offline   Reply With Quote
Old 04-30-2023, 11:24 AM   #949
Amon_Re
Zealot
Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.
 
Posts: 132
Karma: 14644
Join Date: Sep 2015
Device: Kobo Elipsa, Poketbook Inkpad 3 & Boyue Likebook Minas
Quote:
Originally Posted by chaley View Post
Assuming you are running calibre 6.12 or later:
Code:
{#kobo_percent_read:'switch_if($ >= 100, 'finished', $ <= 0, 'unread', 'reading')'}
Hmm, this only works if #kobo_percent_read is 1. If the value is between 2 and 100 the result is "finished".

Last edited by Amon_Re; 04-30-2023 at 01:58 PM.
Amon_Re is offline   Reply With Quote
Old 04-30-2023, 03:31 PM   #950
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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Amon_Re View Post
Hmm, this only works if #kobo_percent_read is 1. If the value is between 2 and 100 the result is "finished".
It works for me using an integer column. What exactly is the type of the kobo_percent_read column? Is it float, int, or (shudder) text? And what exactly are the values in the column?

You might be able to make it work using this template that instructs calibre to treat the values as numbers even if they are declared as text.
Code:
{#kobo_percent_read:'switch_if($ >=# 100, 'finished', $ <=# 0, 'unread', 'reading')'}
chaley is offline   Reply With Quote
Advert
Old 04-30-2023, 04:28 PM   #951
Amon_Re
Zealot
Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.Amon_Re is less competitive than you.
 
Posts: 132
Karma: 14644
Join Date: Sep 2015
Device: Kobo Elipsa, Poketbook Inkpad 3 & Boyue Likebook Minas
Quote:
Originally Posted by chaley View Post
It works for me using an integer column. What exactly is the type of the kobo_percent_read column? Is it float, int, or (shudder) text? And what exactly are the values in the column?

You might be able to make it work using this template that instructs calibre to treat the values as numbers even if they are declared as text.
Code:
{#kobo_percent_read:'switch_if($ >=# 100, 'finished', $ <=# 0, 'unread', 'reading')'}
This one works perfectly, thank you! As far as I can tell the column is an integer, it was created by the Kobo Utilities plugin and shows up as integer in the preferences
Amon_Re is offline   Reply With Quote
Old 06-19-2023, 01:41 AM   #952
ecabot
Junior Member
ecabot began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Mar 2023
Device: none
Moderator Notice
This post is deleted because it a) has nothing to do with templates, and b) is a repeat of this post.

Last edited by chaley; 06-19-2023 at 05:03 AM.
ecabot is offline   Reply With Quote
Old 06-30-2023, 09:26 AM   #953
zardoxnet
Junior Member
zardoxnet began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Dec 2016
Device: android phone
I am working on a metadata plugboard to be used when exporting a book and including all relevant details in the new comment field of the created book. So I have a template program and concatenate all values. The part I am looking for help with is in taking 3 values and printing them out with commas between them. Any of the 3 values might be blank, so I don't want to print a comma for those and don't want a hanging comma.
For example, what I have now, prints out as:
...
<tr>
<td>Identifier:</td>
<td>9781481440967 9781481440950 </td>
</tr>
... or ...
<tr>
<td>Identifier:</td>
<td>9780748120550 asin:B0065JMS64</td>
</tr>

But what I want is:

...
<tr>
<td>Identifier:</td>
<td>9781481440967, 9781481440950 </td>
</tr>
... or ...
<tr>
<td>Identifier:</td>
<td>9780748120550, asin:B0065JMS64</td>
</tr>

Here is my code from the plugboard:

isbn1 = test(field('#isbn_enter'),field('#isbn_enter'),'') ;
isbn2 = test(field('#isbn_p_enter'),field('#isbn_p_enter') ,'');
isbn3 = test(field('#isbn_asin'),strcat('asin:', field('#isbn_asin')),'');
OUTPUT6 = test(strcat(isbn1,isbn2,isbn3),strcat('<tr><td>Ide ntifier:</td><td>', isbn1,' ',isbn2,' ',isbn3,'</td></tr>'),'');

I see a function for creating a list and then printing out that list with separators. However, there are no good examples on how to use the function. Any help?
zardoxnet is offline   Reply With Quote
Old 06-30-2023, 10:01 AM   #954
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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by zardoxnet View Post
I am working on a metadata plugboard to be used when exporting a book and including all relevant details in the new comment field of the created book. So I have a template program and concatenate all values. The part I am looking for help with is in taking 3 values and printing them out with commas between them. Any of the 3 values might be blank, so I don't want to print a comma for those and don't want a hanging comma.
[snip]
Try this:
Code:
program:
	ids = list_remove_duplicates($#isbn_enter & ',' & $#isbn_p_enter & ',' 
		& $#isbn_asin, ',');
	if ids then
		OUTPUT6 = strcat('<tr><td>Identifier:</td><td>', ids, '</td></tr>')
	else
		OUTPUT6 = ''
	fi
This works because list_remove_duplicates():
  • removes empty items as well as duplicates.
  • removes leading and trailing spaces.
  • if the separator is ',' then it (like most of the list functions) rebuilds the list using ', ' (comma space).
  • returns the empty string if the list is empty.
chaley is offline   Reply With Quote
Old 08-01-2023, 01:01 PM   #955
jecilop
Addict
jecilop will be dicovering the secret to cold fusion any day nowjecilop will be dicovering the secret to cold fusion any day nowjecilop will be dicovering the secret to cold fusion any day nowjecilop will be dicovering the secret to cold fusion any day nowjecilop will be dicovering the secret to cold fusion any day nowjecilop will be dicovering the secret to cold fusion any day nowjecilop will be dicovering the secret to cold fusion any day nowjecilop will be dicovering the secret to cold fusion any day nowjecilop will be dicovering the secret to cold fusion any day nowjecilop will be dicovering the secret to cold fusion any day nowjecilop will be dicovering the secret to cold fusion any day now
 
Posts: 260
Karma: 139980
Join Date: Mar 2014
Device: Android
Quote:
Originally Posted by chaley View Post
Starting with calibre 6.17:

This template search will find books that have any extra files in the book's data/ folder:
Code:
template:"""program:has_extra_files()#@#:b:yes"""
@Chaley..I was directed here from such an inquiry in a LibMgmt thread....Just want to say thank you for this!!!
jecilop is offline   Reply With Quote
Old 08-23-2023, 01:49 AM   #956
culytera
Zealot
culytera ought to be getting tired of karma fortunes by now.culytera ought to be getting tired of karma fortunes by now.culytera ought to be getting tired of karma fortunes by now.culytera ought to be getting tired of karma fortunes by now.culytera ought to be getting tired of karma fortunes by now.culytera ought to be getting tired of karma fortunes by now.culytera ought to be getting tired of karma fortunes by now.culytera ought to be getting tired of karma fortunes by now.culytera ought to be getting tired of karma fortunes by now.culytera ought to be getting tired of karma fortunes by now.culytera ought to be getting tired of karma fortunes by now.
 
Posts: 111
Karma: 290364
Join Date: Jul 2021
Device: iPhone
I have a custom column #date_range that's populated via FanFicFare using the date updated and date published metadata. I have a regex for it in FFF's settings:
Code:
## diff dates     1pmonth    2pday        3pyear   4umonth    5uday        6uyear
 dateRange_LIST=>([^\s]+)\s+(\d{1,2})\,\s+(\d{4})\,\s([^\s]+)\s+(\d{1,2})\,\s+(\d{4})=>\1 \2, \3-\4 \5, \6
## same year      1          2            3        4          5
 dateRange_LIST=>([^\s]+)\s+(\d{1,2})\,\s+(\d{4})-([^\s]+)\s+(\d{1,2})\,\s+\3=>\1 \2-\4 \5, \3
## same month     1          2              3            4
 dateRange_LIST=>([^\s]+)\s+(\d{1,2})-\1\s+(\d{1,2})\,\s+(\d{4})=>\1 \2-\3, \4
Example results:

Different dates: January 1, 2022-April 1, 2023
Same year: May 20-August 23, 2023
Same month: August 10-15, 2023
Same day: August 23, 2023

And so I was wondering if this is also possible to do with a column built from other columns + templates since I have published date and updated date columns.
culytera is offline   Reply With Quote
Old 09-14-2023, 11:10 PM   #957
PapaJohn
Enthusiast
PapaJohn began at the beginning.
 
Posts: 35
Karma: 10
Join Date: Feb 2011
Device: Kindle Paperwhite, Kobo Aura One
Quote:
Originally Posted by pchrist7 View Post
Hi All
The following HOWTO was developped in another thread.

Chaley suggested to put it here as well.

Do you have a Kindle ?
Did you ever want Calibre to show "Read Status" of your books in a column ?
Automagically ?

Then the following might for you as well.

You must be running Calibre 0.7.40 or newer to use this.
Also you must use "Fetch annotations" from you Kindle.

The following example is based on the following Kindler requirements:
"What I want is a custom column to show the "Last Opened" Date if Last location read > 95%.
If the book shows >0% but < 95%, I want the column to show "Reading"
And if the book is 0%, or unopened, the column should show "Not Read".


Howto "Fetch annotations" from you Kindle:
Start Calibre,
Connect your Kindle, wait a bit,
Click on the arrow just to the right of the "Send to Device" icon,
choose "Fetch Annotations"
and the Kindle "Book status" is added to the Calibre book details, in the comments.

You should Fetch fresh Annotations everytime you connect your Kindle to get updated information.

This is just an example of what I could get with my K3:

25-12-2010
Last Page Read: Location 7365 (68%)
Location 4603 • Bookmark
Location 4942 • Bookmark
Location 4980 • Bookmark
Location 5984 • Bookmark
Location 7363 • Bookmark


The best/fastest way, but hardest way, to get the needed information into a custom column, is to use Python Template functions.
Sounds scary, but don't worry. Copy/paste is your helper

Simply do as follows:

1) go to Preferences -> Advanced -> Template Functions.

2) in the Function box type: kindle_read_status

3) in the Arg count box type: 4

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 annotations are found, then compare that percent against is_read_pct. 
If the val is larger, then return date, 
if the val is >0 and < is_read_pct return is_reading_str. 
Otherwise return is_not_read_str. 

One usage: {comments:kindle_read_status(95,Not Read,Reading)}
( use the above when defining your custom column )

95 goes into variable is_read_pct
Not Read goes into variable no_page_read_str
Reading goes into variable is_reading_str

Feel free to change the %, the test strings to suit your needs.
Do this in the custom column definition.
5) In the Program Code box, paste the following:
Code:
def evaluate(self, formatter, kwargs, mi, locals, val, is_read_pct,  
				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+).*?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
		elif f > 0:
			return is_reading_str + ': ' + pct + '%'
	except:
		pass
	return no_page_read_str
6) press the Create button, then the Apply button.

7) Still in Preferences, Choose Add your own columns

8) Choose Add custom column bar at the bottom

9) enter the following into your custom column:
Lookup name: read_status
Column Heading: Read Status
Column type: Column built from other columns
Template:
Code:
{comments:kindle_read_status(95,Reading,Not Read)}
10) Choose Apply

11) Click Ok to the Restart Warning

12) Shutdown Calibre

13) Start Calibre

If you followed instructions minutely, you should have a new column showing the "Read Status" for your books.

If you like this functionality, please remember to send some Karma to chaley
https://www.mobileread.com/forums/rep....php?p=1351864

He has been absolutely fantastic and helpfull with this.

If this fails, please try one more time before posting to this thread.
This has been tested by several Kindlers succesfully.

Enjoy

Note: If you want a text returned instead of a date when a book is read
have a look here:
https://www.mobileread.com/forums/sh...&postcount=172

Cant't get this template still work with a 2013 Paperwite in Calibre 6.11 om Mac OS 10.15.7. Don't know if I am doing something wrong or if the template is to old.

Last edited by PapaJohn; 09-14-2023 at 11:16 PM.
PapaJohn is offline   Reply With Quote
Old 10-02-2023, 10:19 PM   #958
sardonica
Junior Member
sardonica began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Oct 2023
Device: kobo libra 2
Keep only initial 2 characters of each word

I'm sure this is the easiest solution ever but the Calibre Template Language guide is going entirely over my head. I'd like to understand how to modify the code below to include the first 2 (rather than 1) characters of each word in text string. But, if the text string is just one word, I'd like to include the first 4 characters. I thought the "\1" indicated the number of characters but was definitely wrong on that front

{#textstring:re([\s]?([^\s])[^\s]+(\s|$),\1)}

Example:
Lord of the Rings --> LoofthRi
Villains --> Vill

Thank you in advance!
sardonica is offline   Reply With Quote
Old 10-03-2023, 05:59 AM   #959
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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by sardonica View Post
I'm sure this is the easiest solution ever but the Calibre Template Language guide is going entirely over my head. I'd like to understand how to modify the code below to include the first 2 (rather than 1) characters of each word in text string. But, if the text string is just one word, I'd like to include the first 4 characters. I thought the "\1" indicated the number of characters but was definitely wrong on that front

{#textstring:re([\s]?([^\s])[^\s]+(\s|$),\1)}

Example:
Lord of the Rings --> LoofthRi
Villains --> Vill

Thank you in advance!
Code:
{series:'contains($, ' ', re($,'\s*(\S{{,2}})\S*(?:\s|$)','\1'), re($, '^(\S{{,4}}).*$', '\1'))'}
chaley is offline   Reply With Quote
Old 10-05-2023, 09:17 PM   #960
sardonica
Junior Member
sardonica began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Oct 2023
Device: kobo libra 2
Thank you so much!!
sardonica is offline   Reply With Quote
Reply

Tags
custom column, tag, tags


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
custom column i need a little help shinken Calibre 3 09-15-2010 03:41 AM
Using Custom Metadata in Save Template EJvdH Calibre 1 07-02-2010 06:06 AM
Accessories Decalgirl Kindle 2 custom skin template srmalloy Amazon Kindle 6 04-09-2010 09:55 PM
Donations for Custom Recipes ddavtian Calibre 5 01-23-2010 04:54 PM
Help understanding custom recipes andersent Calibre 0 12-17-2009 02:37 PM


All times are GMT -4. The time now is 11:27 AM.


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