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 03-31-2021, 10:24 AM   #1
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: 10,854
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Template: Specifying that an identifier does not exist

I am trying to convert these three rules into an advanced one:

Click image for larger version

Name:	2021-03-31 10_57_53-calibre - Preferences - Look & feel.png
Views:	108
Size:	24.7 KB
ID:	186262

Context: the first rule checks for url: identifiers I want to remove from finished fanfics, and the second two check for missing ao3/ffnet identifiers that I want to add to in-progress fanfics. If I see the icon, I then run my Cleanup: Fanfiction action chain to automagically do it.

I have this, which works (I changed a few things around):

Code:
program:
	status = $#fanficstatus;
	publisher = $publisher;
	ids = $identifiers;
	u = select(ids, 'url');
 	a = select(ids, 'ao3');
	f = select(ids, 'ffnet');

	if 
		u
		&& '(Archive of Our Own|Fanfiction.net)' in publisher  
		&& '(Completed|Abandoned|Oneshot)' in status
	then "metadata.png:"

	elif
		u
		&& a
		&& publisher = 'Archive of Our Own'
		&& status = 'In-Progress'
	then "metadata.png:"

	elif
		u
		&& f
		&& publisher = 'FanFiction.net'
		&& status = 'In-Progress'
	then "metadata.png:"

	fi
Except that && a and && f both specify "if these identifiers exist." How do I get it to instead specify "if these identifiers do not exist"?

Also, how would I specificy "if (A or F) exist" for the first part?

I see this part but I don't really understand how to make the syntax work

Code:
or_expression   ::= and_expression [ '||' and_expression ]*
and_expression  ::= not_expression [ '&&' not_expression ]*
not_expression  ::= [ '!' not_expression ]* | compare_exp

Last edited by ownedbycats; 03-31-2021 at 11:04 AM.
ownedbycats is offline   Reply With Quote
Old 03-31-2021, 11:39 AM   #2
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,393
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
First, note that the test of 'u' is the same in all the condition clauses and you never subsequently use 'u', so it can be factored out.

You use 'unary not' (!) to invert a condition, in your case to return True if the variable is empty.

Given the above, I think you want:
Code:
program:
	if select(ids, 'url') then
		status = $#fanficstatus;
		publisher = $publisher;
		ids = $identifiers;
		a = select(ids, 'ao3');
		f = select(ids, 'ffnet');

		if 
			   (a || f)
			&& '(Archive of Our Own|Fanfiction.net)' in publisher  
			&& '(Completed|Abandoned|Oneshot)' in status
		then "metadata.png:"

		elif
			   !a
			&& publisher = 'Archive of Our Own'
			&& status = 'In-Progress'
		then "metadata.png:"

		elif
			   !f
			&& publisher = 'FanFiction.net'
			&& status = 'In-Progress'
		then "metadata.png:"

		fi
	fi
chaley is offline   Reply With Quote
Advert
Old 03-31-2021, 04:11 PM   #3
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: 10,854
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I had to move ids = $identifiers; to the first line to prevent an error, but now I'm getting odd results.

e.g.

Status: In-Progress
Publisher: Archive of Our Own
identifiers: url, ao3
Intended result: null
Actual result: metadata.png

I am getting the same thing for FanFiction.net/ffnet.

modifying my original code like this does get the intended results though:

Code:
program:
	status = $#fanficstatus;
	publisher = $publisher;
	ids = $identifiers;
	u = select(ids, 'url');
 	a = select(ids, 'ao3');
	f = select(ids, 'ffnet');

	if 
		(a || f)
		&& u
		&& '(Archive of Our Own|Fanfiction.net)' in publisher  
		&& '(Completed|Abandoned|Oneshot)' in status
	then "metadata.png:"

	elif
		!a
		&& u
		&& publisher = 'Archive of Our Own'
		&& status = 'In-Progress'
	then "metadata.png:"

	elif
		!f
		&& u
		&& publisher = 'FanFiction.net'
		&& status = 'In-Progress'
	then "metadata.png:"

	fi

Last edited by ownedbycats; 03-31-2021 at 04:21 PM.
ownedbycats is offline   Reply With Quote
Old 03-31-2021, 04:34 PM   #4
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,393
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
modifying my original code like this does get the intended results though:
This doesn't make sense to me. As far as I can see the results of the two templates should be identical. Either
  • I am misunderstanding
  • The template language processor is broken
  • The data is not what I think it must be.
Would you be willing to send me a zipped copy of your metadata.db to "ghg-cal-stuff at charleshaley dot org", making the obvious substitutions? Don't send the books. With that I can run your templates on your data and perhaps figure out why I am confused. Do note that if you send me the db I will know a lot about your library, which you may or may not be happy with. I will totally understand if you don't send it.
chaley is offline   Reply With Quote
Old 03-31-2021, 04:38 PM   #5
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: 10,854
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
My current database is kinda bulky due to Audit Log, but I'll copy a few books to a test DB and if it's replicated there email it.
ownedbycats is offline   Reply With Quote
Advert
Old 03-31-2021, 05:07 PM   #6
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: 10,854
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I replicated the issue in a testing library and sent the database from an outlook.com email address.
ownedbycats is offline   Reply With Quote
Old 03-31-2021, 05:58 PM   #7
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,393
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
The problem seems to be you using '=' instead of '==' to do comparisons. The first does an assignment and returns the value being assigned. The second does the comparison.

Does this template do what you expect? I changed lines 15, 16, 20, and 21. Sorry I didn't notice the error before post #2.
Code:
program:
ids = $identifiers;
if select(ids, 'url') then
	status = $#fanficstatus;
	publisher = $publisher;
	a = select(ids, 'ao3');
	f = select(ids, 'ffnet');
	if
		(a || f)
		&& '(Archive of Our Own|Fanfiction.net)' in publisher
		&& '(Completed|Abandoned|Oneshot)' in status
		then "metadata.png:"
	elif
		!a
		&& publisher == 'Archive of Our Own'
		&& status == 'In-Progress'
	then "metadata.png:"
	elif
		!f
		&& publisher == 'FanFiction.net'
		&& status == 'In-Progress'
		then "metadata.png:"
	fi
fi
FWIW: people have mistaken assignment for equality since forever. That is one reason why "newer" languages don't allow assignment as an expression or use a different operator such as ":=". It is too late for me to make either change because it would surely break existing templates.
chaley is offline   Reply With Quote
Old 03-31-2021, 08:46 PM   #8
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: 10,854
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
That works. I will try to remember the double == in the future.
ownedbycats is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Template: saving template tester when restarting Calibre ownedbycats Library Management 14 03-29-2021 05:57 PM
Template: Converting a search & replace into a template ownedbycats Library Management 11 03-26-2021 04:32 AM
Using built-in template functions in a custom template function ilovejedd Library Management 4 01-28-2018 12:20 PM
How would one create an identifier template? Sidetrack Library Management 0 06-06-2014 01:38 AM


All times are GMT -4. The time now is 02:27 PM.


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