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 07-23-2023, 11:42 AM   #646
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 9,034
Karma: 62040591
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
In my specific case, I've started copying the previous last-read dates to #admintags, as 'read:2020-04-16'.

Here's the template I used to make the list:

Code:
program:

	most_recent= format_date($$#lastread, 'yyyy-MM-dd');
	old_dates= list_re($#admintags, ',', 'read:', ' ');

	date_list= list_sort(list_union(most_recent, old_dates, ','), 0, ',')
Unfortunately, short of editing the read: tag entries I'm not sure if it's possible to do it while building the list.

Additionally: is using list_re to replace 'read:' with a space the proper method?
ownedbycats is online now   Reply With Quote
Old 07-23-2023, 12:04 PM   #647
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,862
Karma: 7036057
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Unfortunately, short of editing the read: tag entries I'm not sure if it's possible to do it while building the list.
It is certainly possible, but without knowing the processing sequence(s) and seeing all the processing I can't know what would be the most efficient. And it might not matter if these are action chains templates you run on-demand.
Quote:
Additionally: is using list_re to replace 'read:' with a space the proper method?
In this template, probably. If 'read:' can appear only has the beginning of a date tag then
Code:
old_dates= re($#admintags, ',', 'read:', ' ');
works and would be faster.
chaley is offline   Reply With Quote
Advert
Old 07-25-2023, 09:55 AM   #648
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 9,034
Karma: 62040591
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Due to people posting non-template questions here, I made a new thread for small library management questions:

https://www.mobileread.com/forums/sh...d.php?t=355273
ownedbycats is online now   Reply With Quote
Old 09-20-2023, 09:58 PM   #649
theodduck
Junior Member
theodduck began at the beginning.
 
theodduck's Avatar
 
Posts: 4
Karma: 10
Join Date: Jul 2023
Device: Onyx Boox Poke 5, Nova 3
Question

What would be the best way to remove/replace a list of special characters from titles when saving to disk/sending to device? I'd like to make sure certain characters like colons and commas aren't included and I don't like that Calibre defaults to replacing colons with an underscore. I'm not a coder so I'm kind of fumbling my way through this.

So far I've stumbled through some posts and the documentation to get the following to replace colons with nothing, but I'm not sure how to make it do the same for additional characters
Code:
{title: re(":","")}

By some miracle, I've come up with the following to do the above AND limit the file name length, so if the solution could be incorporated into this, that'd be even better.
Code:
{title:'sublist(re($, ":", ""), 0, 8, " ")'}
If there is a different way I should be doing this, let me know.
theodduck is offline   Reply With Quote
Old 09-22-2023, 08:08 AM   #650
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,129
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by theodduck View Post
What would be the best way to remove/replace a list of special characters from titles when saving to disk/sending to device? I'd like to make sure certain characters like colons and commas aren't included and I don't like that Calibre defaults to replacing colons with an underscore. I'm not a coder so I'm kind of fumbling my way through this.

So far I've stumbled through some posts and the documentation to get the following to replace colons with nothing, but I'm not sure how to make it do the same for additional characters
Code:
{title: re(":","")}
Code:
{title: re("[:\,]","")}
The comma here is escaped with a backslash. Some characters don't need to be escaped. For example if you want to also remove characters like semicolons and underscores.

Code:
{title: re("[:\,;_]","")}
Trial and error should guide you into what needs to be escaped and what does not need.
capink is offline   Reply With Quote
Advert
Old 09-22-2023, 02:58 PM   #651
theodduck
Junior Member
theodduck began at the beginning.
 
theodduck's Avatar
 
Posts: 4
Karma: 10
Join Date: Jul 2023
Device: Onyx Boox Poke 5, Nova 3
Quote:
Originally Posted by capink View Post
(snip)
Yes, this works great! Thanks for pointing me in the right direction.
theodduck is offline   Reply With Quote
Old 09-23-2023, 11:17 PM   #652
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 9,034
Karma: 62040591
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Is there any functional difference between $$#timesread>#0 or $$#timesread>=#1?

Code:
program:
	status = readstatus();
	times = $$#timesread;

	switch_if(
		status=='currentlyreading' && times>#0, 'Currently Rereading',
		status=='currentlyreading', 'Currently Reading',
		status=='toberead' && times>#0, 'To Be Reread',
		status=='toberead', 'To Be Read',
		status=='read', 'Read',
		status=='unread', 'Unread',
		status=='didnotfinish', 'Did Not Finish',
		''
	)
ownedbycats is online now   Reply With Quote
Old 09-24-2023, 03:15 PM   #653
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,862
Karma: 7036057
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Is there any functional difference between $$#timesread>#0 or $$#timesread>=#1?

Code:
program:
	status = readstatus();
	times = $$#timesread;

	switch_if(
		status=='currentlyreading' && times>#0, 'Currently Rereading',
		status=='currentlyreading', 'Currently Reading',
		status=='toberead' && times>#0, 'To Be Reread',
		status=='toberead', 'To Be Read',
		status=='read', 'Read',
		status=='unread', 'Unread',
		status=='didnotfinish', 'Did Not Finish',
		''
	)
No difference in meaning or performance. There are usually multiple ways to express a relational conditional. Often one of them makes more sense to a reader. In your case, to me ">#0" better expresses the logic.

You could even do
Code:
! $$#timesread<=#0
chaley is offline   Reply With Quote
Old 10-11-2023, 03:41 PM   #654
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 9,034
Karma: 62040591
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Just out of curiosity, I put this in the template tester:

Quote:
program:

mydate = '2000';

format_date(mydate, 'yyyy-MM-dd');
I always end up with [year]-10-15. Where does the October 15th date come from? I thought it'd be the current date, but it's only the 11th where I live.
ownedbycats is online now   Reply With Quote
Old 10-11-2023, 04:17 PM   #655
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,862
Karma: 7036057
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Just out of curiosity, I put this in the template tester:



I always end up with [year]-10-15. Where does the October 15th date come from? I thought it'd be the current date, but it's only the 11th where I live.
The template processor uses calibre's date parser, which is dateutil. When it parses a date, missing fields come from "default". In calibre, default is specified as
Code:
func = datetime.utcnow if assume_utc else datetime.now
default = func().replace(day=15, hour=0, minute=0, second=0, microsecond=0,
                tzinfo=_utc_tz if assume_utc else _local_tz)
The variable assume_utc is False.

As such, a missing month is the current local month and a missing day is the 15th. A missing time becomes midnight. I don't know if one can have a missing year, but if so then it would be the current year.
chaley is offline   Reply With Quote
Old 10-18-2023, 06:14 PM   #656
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 9,034
Karma: 62040591
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Code:
program:

dates = list_count($#readdates, ',');

readcount = $$#timesread;

if dates != readcount then 'yes' fi
When both #readdates (tag-like) and timesread (integer) are undefined, this returns 'yes.' Why?
ownedbycats is online now   Reply With Quote
Old 10-18-2023, 06:18 PM   #657
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,862
Karma: 7036057
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Code:
program:

dates = list_count($#readdates, ',');

readcount = $$#timesread;

if dates != readcount then 'yes' fi
When both #readdates (tag-like) and timesread (integer) are undefined, this returns 'yes.' Why?
Because the string '0' (zero, list_count()) doesn't equal the string 'none' (raw_field()). If you used !=# then IIRC zero would equal none.
chaley is offline   Reply With Quote
Old 10-18-2023, 06:20 PM   #658
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 9,034
Karma: 62040591
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Ah yeah, adding a hash sign fixes that. Thanks.
ownedbycats is online now   Reply With Quote
Old 10-29-2023, 02:55 PM   #659
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,129
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
When writing a template function, is there a way to test whether the function is called from a python template or not? If so, can it return a python object (e.g. python list)? or would it result in an error?
capink is offline   Reply With Quote
Old 10-29-2023, 05:17 PM   #660
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,862
Karma: 7036057
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by capink View Post
When writing a template function, is there a way to test whether the function is called from a python template or not?
Not easily. You can examine the stack and see if "call" is method name in the calling frame, but I think this might be brittle. See below for another idea.
Quote:
If so, can it return a python object (e.g. python list)? or would it result in an error?
Yes, a python template function can return a python object. The formatter returns it to the calling template unchanged.

I suggest you provide two functions, one that returns a string and one that returns whatever. Alternately, provide an optional parameter that tells the function what to return.

Note that if a python template function returns a list then the formatter tries to convert the returned value to a string with ', '.join(returned_value). Of course this only works if the list contains strings.
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Library Management: various questions not worth their own thread ownedbycats Library Management 156 07-23-2024 11:45 PM
[Metadata Source Plugin] Questions regarding parse select, docs and ref templates Boilerplate4U Development 13 07-07-2020 02:35 AM
Questions on Kobo [Interfered with another thread topic] spdavies Kobo Reader 8 10-12-2014 11:37 AM
[OLD Thread] Some questions before buying the fire. darthreader13 Kindle Fire 7 05-10-2013 09:19 PM
Thread management questions meme Feedback 6 01-31-2011 05:07 PM


All times are GMT -4. The time now is 06:36 PM.


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