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-18-2021, 02:13 PM   #61
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: 12,027
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Sorry, not too clear. Currently this returns the first alphanumeric character of title_sort. I thought it'd be possible to combine all the numeric characters into a single 0-9 category.
Still confused. What does it mean to combine numbers into a category? Can you give some examples?
chaley is offline   Reply With Quote
Old 04-18-2021, 02:26 PM   #62
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,528
Karma: 64500175
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Click image for larger version

Name:	2021-04-18 14_23_50-Window.png
Views:	1561
Size:	7.2 KB
ID:	186677

For the tag browser. I don't have that many book titles starting with numeric characters specifically so I thought to make a single 0-9 instead of 0, 1, 2, 4, 5, 9...
ownedbycats is online now   Reply With Quote
Advert
Old 04-18-2021, 02:38 PM   #63
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: 12,027
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Attachment 186677

For the tag browser. I don't have that many book titles starting with numeric characters specifically so I thought to make a single 0-9 instead of 0, 1, 2, 4, 5, 9...
I think this does what you want. Two versions

TPM:
Code:
{title_sort:'contains(t=uppercase(re($, '^\W*(\w).*$','\1')), '\d', '0-9', t)'}
GPM:
Code:
program:
	t = uppercase(re($title_sort, '^\W*(\w).*$','\1'));
	if '\d' in t then '0-9' else t fi
chaley is offline   Reply With Quote
Old 04-18-2021, 03:50 PM   #64
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,528
Karma: 64500175
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
That works. Thank you.

A minor question about the template tester. Heres a template I am making for my 'mark as read' action chain:

Code:
program:
	
	if 
		check_yes_no('#onkobo', 1, 0, 0)
		then format_date(today(),'iso')
else $$#lastread
fi
In the screenshot is a book that is affected by the if statement and returns 'today'.

However, changing $$#lastread (raw field) to $#lastread in the else statement changes it slightly. Why does this occur?

edit: wait, I think it's because time elapses...
Attached Thumbnails
Click image for larger version

Name:	2021-04-18_155011.png
Views:	863
Size:	45.9 KB
ID:	186678  

Last edited by ownedbycats; 04-18-2021 at 04:00 PM.
ownedbycats is online now   Reply With Quote
Old 04-18-2021, 05:25 PM   #65
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: 12,027
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
However, changing $$#lastread (raw field) to $#lastread in the else statement changes it slightly. Why does this occur?

edit: wait, I think it's because time elapses...
Yes, time does pass.

However $$X and $X are not the same thing. The raw_field version ($$) returns whatever is the raw data for the field. The field version ($) returns a formatted value. How those two differ depends on many things such as tweaks, column formats, and calibre default formats.
chaley is offline   Reply With Quote
Advert
Old 04-18-2021, 05:37 PM   #66
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,528
Karma: 64500175
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
#lastread is a column that shows just the date, so that $#lastread returns only the date (giving me a timestamp of 00:00:00 if I actually run it to modify the column) and $$#lastread gave me the full timestamp.
ownedbycats is online now   Reply With Quote
Old 04-20-2021, 08:39 PM   #67
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,139
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
@chaley: is there a way to make the template output new lines. For example if I want to output all formats for a book separated by a new line? Or do I have to wrap the call to the formatter to maybe replace '\\n' with a new line (in Action Chains)?

Edit: Replacing '\\n' with newlines would be a really bad idea it can mess up file paths which can have the same character. I will think of a safer representation for a new line. Maybe a new_line() function that inserts a non-printable character.

Last edited by capink; 04-20-2021 at 08:56 PM.
capink is offline   Reply With Quote
Old 04-21-2021, 05:04 AM   #68
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: 12,027
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by capink View Post
@chaley: is there a way to make the template output new lines. For example if I want to output all formats for a book separated by a new line? Or do I have to wrap the call to the formatter to maybe replace '\\n' with a new line (in Action Chains)?

Edit: Replacing '\\n' with newlines would be a really bad idea it can mess up file paths which can have the same character. I will think of a safer representation for a new line. Maybe a new_line() function that inserts a non-printable character.
The lexical analyser doesn't do any character escaping. The exception, which it gets wrong, is escaping quotes for example 'aa\'bb' that ends up as the string aa\'bb. Yes, the backslash is still there, which is wrong. I am looking for ways to fix this without breaking all strings containing backslashes.

If we use a "newline()" function, and presumably strcat(), then why not have it put a real newline in the string?

Note that by default leading and trailing whitespace is stripped (strip()). If you don't want that then call the formatter with strip_results=False.

EDIT: if strip_results is True then all white space, including newlines, is turned into a single space.

Last edited by chaley; 04-21-2021 at 06:01 AM.
chaley is offline   Reply With Quote
Old 04-21-2021, 06:29 AM   #69
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: 12,027
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Here is a test version of formatter.py that supports a newline() function. It returns an actual newline character. As I said above, if you call the formatter with strip_results=False then the character(s) will not be removed.

I tested it with this template and it worked
Code:
program: strcat('a', newline(), 'b')
Attached Files
File Type: zip formatter.zip (9.2 KB, 700 views)
chaley is offline   Reply With Quote
Old 04-21-2021, 08:21 AM   #70
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,139
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
It is working. I also strip the leading and trailing white space after that using strip().

Code:
def safe_format(fmt, kwargs_, error_value, book, **kwargs):
    output = SafeFormat().safe_format(fmt, kwargs_, error_value, book, strip_results=False, **kwargs)
    return output.strip()
capink is offline   Reply With Quote
Old 04-21-2021, 10:27 AM   #71
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: 12,027
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by capink View Post
It is working. I also strip the leading and trailing white space after that using strip().

Code:
def safe_format(fmt, kwargs_, error_value, book, **kwargs):
    output = SafeFormat().safe_format(fmt, kwargs_, error_value, book, strip_results=False, **kwargs)
    return output.strip()
The change is now in calibre source.

In addition, I improved the performance of the formatter parser by using table lookup instead of a series of 'if's to generate the interpretable syntax tree. Could you use the new version? I don't think I broke anything, but I have said that before.
chaley is offline   Reply With Quote
Old 04-21-2021, 10:36 AM   #72
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,139
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
Thanks. I am using it now and it seems to be working OK. But newline() is not highlighted and does not appear in the function reference, but it works as expected.
capink is offline   Reply With Quote
Old 04-21-2021, 11:01 AM   #73
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: 12,027
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by capink View Post
Thanks. I am using it now and it seems to be working OK. But newline() is not highlighted and does not appear in the function reference, but it works as expected.
It is a function, not a keyword, so it isn't highlighted. I thought about making it a keyword but decided against it to avoid clashes with identifiers in existing templates.

You are right, I forgot to add the function to the function list. I will do that.

Question: for most formatter calls the newline() function won't do anything because the result has all contiguous white space converted to a single blank. It is then stripped. For example the template result "\nA \r\t\n B " becomes "A B". I am thinking of changing that behavior for GPM templates (but not SFM templates), removing the conversion-to-one-blank step. If I do then the above string would become "A \r\t\n B" (the leading and trailing whitespace is stripped but internal whitespace is not modified). I could also do strip(' '), removing leading & trailing blanks but leaving other whitespace intact. In this case the example result would be "\nA \r\t\n B" This change would make the newline() function generally usable and would permit formatting using tabs. (Of course that would require adding a tab() function.)

It is possible that someone has GPM templates that depend on the current callapse-white-space behavior, but I think the chances are very low, and in any event the template can be changed not to depend on collapsing spaces together.

I lean toward removing collapsing internal white space and stripping only blanks. What do you think?

BTW: the above change would mean you don't need to set strip_results because it would still do the strip() that you are doing.
chaley is offline   Reply With Quote
Old 04-21-2021, 11:34 AM   #74
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: 12,027
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Another thought: instead of newline() why not have character('name') where 'name' is the letter used in the escape? That lets us add more characters without risk of breaking things or needing to introduce more functions.

We could adapt names from the python standard escape sequence table.
Code:
\\ - backslash
\' - quote (')
\" - double_quote (")
\b - backspace
\n - newline (LF)
\r - return (CR)
\t - tab (TAB)
Examples:
Code:
character('newline') returns '\n'
character('return') returns '\r'
character('tab') returns '\t'
character('backspace') returns '\b'
character('backslash') returns '\\'
chaley is offline   Reply With Quote
Old 04-21-2021, 11:56 AM   #75
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,139
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by chaley View Post
It is a function, not a keyword, so it isn't highlighted. I thought about making it a keyword but decided against it to avoid clashes with identifiers in existing templates.

You are right, I forgot to add the function to the function list. I will do that.
Functions turn into blue once I add the parenthesis. I think adding to the function list would do it. e.g. In the screenshot below, the strcat is blue while the newline is not.

Quote:
Originally Posted by chaley View Post
Question: for most formatter calls the newline() function won't do anything because the result has all contiguous white space converted to a single blank. It is then stripped. For example the template result "\nA \r\t\n B " becomes "A B". I am thinking of changing that behavior for GPM templates (but not SFM templates), removing the conversion-to-one-blank step. If I do then the above string would become "A \r\t\n B" (the leading and trailing whitespace is stripped but internal whitespace is not modified). I could also do strip(' '), removing leading & trailing blanks but leaving other whitespace intact. In this case the example result would be "\nA \r\t\n B" This change would make the newline() function generally usable and would permit formatting using tabs. (Of course that would require adding a tab() function.)

It is possible that someone has GPM templates that depend on the current callapse-white-space behavior, but I think the chances are very low, and in any event the template can be changed not to depend on collapsing spaces together.

I lean toward removing collapsing internal white space and stripping only blanks. What do you think?

BTW: the above change would mean you don't need to set strip_results because it would still do the strip() that you are doing.
Sounds very good to me.

Quote:
Originally Posted by chaley View Post
Another thought: instead of newline() why not have character('name') where 'name' is the letter used in the escape? That lets us add more characters without risk of breaking things or needing to introduce more functions.

We could adapt names from the python standard escape sequence table.
Code:
\\ - backslash
\' - quote (')
\" - double_quote (")
\b - backspace
\n - newline (LF)
\r - return (CR)
\t - tab (TAB)
Examples:
Code:
character('newline') returns '\n'
character('return') returns '\r'
character('tab') returns '\t'
character('backspace') returns '\b'
character('backslash') returns '\\'
That is definitely much better.
Attached Thumbnails
Click image for larger version

Name:	2.png
Views:	835
Size:	69.4 KB
ID:	186719  
capink 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 171 11-02-2024 05:51 PM
[Metadata Source Plugin] Questions regarding parse select, docs and ref templates Boilerplate4U Development 13 07-07-2020 03:35 AM
Questions on Kobo [Interfered with another thread topic] spdavies Kobo Reader 8 10-12-2014 12:37 PM
[OLD Thread] Some questions before buying the fire. darthreader13 Kindle Fire 7 05-10-2013 10:19 PM
Thread management questions meme Feedback 6 01-31-2011 06:07 PM


All times are GMT -4. The time now is 08:35 PM.


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