08-19-2024, 06:31 AM | #16 |
Evangelist
Posts: 418
Karma: 41524
Join Date: Sep 2011
Device: Kobo Libra 2 & Clara BW
|
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. |
08-19-2024, 07:02 AM | #17 | ||
Grand Sorcerer
Posts: 12,006
Karma: 7257321
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
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:
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) 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 |
||
08-19-2024, 07:12 AM | #18 |
Grand Sorcerer
Posts: 12,006
Karma: 7257321
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
|
08-21-2024, 02:39 PM | #19 |
Addict
Posts: 206
Karma: 1271468
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.
|
08-21-2024, 02:46 PM | #20 |
Grand Sorcerer
Posts: 11,378
Karma: 230167340
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.
|
08-21-2024, 03:13 PM | #21 | |
Evangelist
Posts: 418
Karma: 41524
Join Date: Sep 2011
Device: Kobo Libra 2 & Clara BW
|
Quote:
|
|
08-21-2024, 03:16 PM | #22 | |
Evangelist
Posts: 418
Karma: 41524
Join Date: Sep 2011
Device: Kobo Libra 2 & Clara BW
|
Quote:
I'd only use it if I couldn't otherwise choose what to read next. Hasn't happened yet. |
|
|
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 |