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 08-19-2024, 06:31 AM   #16
foosion
Addict
foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.
 
Posts: 205
Karma: 4562
Join Date: Sep 2011
Device: Kobo Libra 2 & Clara BW
Quote:
Originally Posted by chaley View Post
Which one of those two? They are implemented very differently.
Is there documentation which shows these functions (these two and the ones in the function you posted)? Or do I need to browse the source code?

It would be good to learn how to write things myself.

In the meanwhile, whichever is easier.

Last edited by foosion; 08-19-2024 at 06:33 AM.
foosion is offline   Reply With Quote
Old 08-19-2024, 07:02 AM   #17
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,893
Karma: 7042567
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by foosion View Post
Is there documentation which shows these functions (these two and the ones in the function you posted)? Or do I need to browse the source code?

It would be good to learn how to write things myself.
Some of the API is documented in https://manual.calibre-ebook.com/dev...rts-of-calibre.

However, for the kinds of things you are trying to do it is usually best to look at existing code that does something similar.

Quote:
In the meanwhile, whichever is easier.
Here is code to do both. The bit you want replaces the two "view_action" lines.
Code:
		# select the random row in the booklist
		view = gui.current_view()
		view.select_rows(set((random_id,)))

		# display a dialog
		mi = db.new_api.get_proxy_metadata(random_id)
		from calibre.gui2 import info_dialog
		data_to_show = (
			f"Series: {mi.format_field('series')[1]}",
			f"Tags: {mi.format_field('tags')[1]}",
			f"My Bool: {mi.format_field('#mybool')[1]}"
		)
		msg = '<br>'.join(data_to_show)
		info_dialog(gui, f"Random book: {mi.get('title')}", msg, show=True)
You can use the template tester in python mode to play, which is easier and faster than creating template actions or altering calibre source. For example, here is the code from above usable as a python template. It is only the rist few lines that are different.

Code:
python:
def evaluate(book, context):
	db = context.db
	from calibre.gui2.ui import get_gui
	gui = get_gui()
	db = gui.current_db
	ids = list(db.new_api.search('#mybool:true and formats:epub'))
	if ids:
		import random
		random_id = random.choice(ids)
#		view_action = gui.iactions['View']
#		view_action.view_format_by_id(random_id, 'EPUB', open_at=None)

		# select the random row.
		view = gui.current_view()
		view.select_rows(set((random_id,)))

		# display a dialog
		mi = db.new_api.get_proxy_metadata(random_id)
		from calibre.gui2 import info_dialog
		data_to_show = (
			f"Series: {mi.format_field('series')[1]}",
			f"Tags: {mi.format_field('tags')[1]}",
			f"My Book: {mi.format_field('#mybool')[1]}"
		)
		msg = '<br>'.join(data_to_show)
		info_dialog(gui, f"Random book: {mi.get('title')} ({str(random_id)})", msg, show=True)		
	return 'a string'

Last edited by chaley; 08-19-2024 at 07:13 AM. Reason: Typo
chaley is offline   Reply With Quote
Old 08-19-2024, 07:12 AM   #18
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,893
Karma: 7042567
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Another bit of important documentation: the book Metadata object api: https://manual.calibre-ebook.com/gen...tadata-objects
chaley is offline   Reply With Quote
Old Today, 02:39 PM   #19
jackm8
Groupie
jackm8 ought to be getting tired of karma fortunes by now.jackm8 ought to be getting tired of karma fortunes by now.jackm8 ought to be getting tired of karma fortunes by now.jackm8 ought to be getting tired of karma fortunes by now.jackm8 ought to be getting tired of karma fortunes by now.jackm8 ought to be getting tired of karma fortunes by now.jackm8 ought to be getting tired of karma fortunes by now.jackm8 ought to be getting tired of karma fortunes by now.jackm8 ought to be getting tired of karma fortunes by now.jackm8 ought to be getting tired of karma fortunes by now.jackm8 ought to be getting tired of karma fortunes by now.
 
jackm8's Avatar
 
Posts: 180
Karma: 1253386
Join Date: Nov 2015
Device: none
I don't bother randomising things. I just pick something and go with it. It's like browsing for books in a library or bookstore. I love reading random books, the less I know about them the better. I'll often go and read something that's mentioned in one book, or the other, I avoid descriptions and reviews and just read it blindly. White Mischief was one of those. I can't even remember why I had it on my device, probably it was in some way mentioned in connection with Black Mischief. I had it untouched at least for a year. I only had phone at hand, and I randomly took it up while waiting for something, and it soon supplanted whatever I was reading then, and it was a blast.
jackm8 is offline   Reply With Quote
Old Today, 02:46 PM   #20
Sirtel
Grand Sorcerer
Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.Sirtel ought to be getting tired of karma fortunes by now.
 
Sirtel's Avatar
 
Posts: 10,921
Karma: 226731282
Join Date: Jan 2014
Location: Estonia
Device: Kobo Sage & Libra 2
I never read something randomly. I don't read reviews or recommendations, but I do read the synopsis and choose my next read based on that, and on my mood. As I only read certain genres and am not interested in many others, picking a book not knowing what it is about is out of the question for me. There are too many genres and themes I just haven't the slightest interest in.
Sirtel is offline   Reply With Quote
Old Today, 03:13 PM   #21
foosion
Addict
foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.
 
Posts: 205
Karma: 4562
Join Date: Sep 2011
Device: Kobo Libra 2 & Clara BW
Quote:
Originally Posted by jackm8 View Post
I don't bother randomising things. I just pick something and go with it. It's like browsing for books in a library or bookstore. I love reading random books, the less I know about them the better. I'll often go and read something that's mentioned in one book, or the other, I avoid descriptions and reviews and just read it blindly. White Mischief was one of those. I can't even remember why I had it on my device, probably it was in some way mentioned in connection with Black Mischief. I had it untouched at least for a year. I only had phone at hand, and I randomly took it up while waiting for something, and it soon supplanted whatever I was reading then, and it was a blast.
I may or may not ever actually use this, but I was curious how I'd implement the thought. It's more of an educational project.
foosion is offline   Reply With Quote
Old Today, 03:16 PM   #22
foosion
Addict
foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.
 
Posts: 205
Karma: 4562
Join Date: Sep 2011
Device: Kobo Libra 2 & Clara BW
Quote:
Originally Posted by Sirtel View Post
I never read something randomly. I don't read reviews or recommendations, but I do read the synopsis and choose my next read based on that, and on my mood. As I only read certain genres and am not interested in many others, picking a book not knowing what it is about is out of the question for me. There are too many genres and themes I just haven't the slightest interest in.
I'm not choosing a random book from the set of all books; I'm choosing a random book from the set of books I chose to put in my Calibre library and then the subset that I chose to put on my Kobo. I have entirely too many unread books in my Calibre library.

I'd only use it if I couldn't otherwise choose what to read next. Hasn't happened yet.
foosion is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to assign Pick a Random Book to a keyboard combination? jamesgl Calibre 3 05-14-2022 05:54 PM
Pick multiple random books? BookJunkieLI Library Management 5 05-24-2020 11:10 AM
"Pick Random Book" - not so random?? Chris_Snow Library Management 3 09-15-2013 06:44 PM
Adding "Pick a Random Book" in Sharing over the net ippopom Recipes 2 01-13-2013 04:32 AM
Do you pick the book first or do you look for books available on your device? Bob Russell Which one should I buy? 21 09-08-2008 12:34 PM


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


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