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 Yesterday, 06:46 PM   #1
foosion
Groupie
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: 189
Karma: 4562
Join Date: Sep 2011
Device: Kobo Libra 2 & Clara BW
Pick a random book?

I'd like to create something that goes through all of my Calibre books, finds those that have the onkobo column checked but doesn't have a date in the finished column, then choose one at random.

Something like:

Code:
import random

unfinished = [book for books if book.onkobo and not book.finished]
book = random.choice(unfinished)
show(book.title, book.author)
How would I do this?
foosion is offline   Reply With Quote
Old Yesterday, 07:33 PM   #2
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 30,225
Karma: 57978960
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
I have a VL for 'To Read'
Code:
Not #finished:>12/31/2000 and formats:true and not formats:other and not #usertags:split_up
finished is a date (2000 is my abandoned date)
usertags is what it says , I tag there when I use Epub Split (PI) on a boxed set
So, if it has a format and not fand any of the other, it represents my (outta control) TBR pile
Once that VL is active, you just use the dice Icon (select a Random Book)
Note: You may need to add it to a toolbar
theducks is offline   Reply With Quote
Advert
Old Yesterday, 07:49 PM   #3
foosion
Groupie
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: 189
Karma: 4562
Join Date: Sep 2011
Device: Kobo Libra 2 & Clara BW
Goes off to figure out virtual libraries.



I like the idea of tracking abandoned books.
foosion is offline   Reply With Quote
Old Yesterday, 07:55 PM   #4
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,894
Karma: 226731282
Join Date: Jan 2014
Location: Estonia
Device: Kobo Sage & Libra 2
Quote:
Originally Posted by foosion View Post
Goes off to figure out virtual libraries.



I like the idea of tracking abandoned books.
You can also use saved searches instead of virtual libraries.

Based on your post, it would be something like #onkobo:true and #finished:false
Sirtel is offline   Reply With Quote
Old Yesterday, 08:31 PM   #5
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 30,225
Karma: 57978960
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
The reason I prefer VL's is because you can use them in conjunction with the Tag Browser.
Show To Read and filter by Science Fiction
theducks is offline   Reply With Quote
Advert
Old Yesterday, 09:20 PM   #6
foosion
Groupie
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: 189
Karma: 4562
Join Date: Sep 2011
Device: Kobo Libra 2 & Clara BW
Quote:
Originally Posted by Sirtel View Post
You can also use saved searches instead of virtual libraries.

Based on your post, it would be something like #onkobo:true and #finished:false
Even simpler.


Last edited by foosion; Yesterday at 09:29 PM.
foosion is offline   Reply With Quote
Old Yesterday, 10:12 PM   #7
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,124
Karma: 62844539
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Quote:
Originally Posted by foosion View Post
I like the idea of tracking abandoned books.
I have a stored template for tracking read status and for it I defined did-not-finished by adding 'dnf' to the#admintags column.

Code:
program:

percent = $$#percentread;

	if 'dnf' inlist $#admintags
	then 'didnotfinish'

	elif percent >=#1 && percent <=#99
	then 'currentlyreading' 

	elif $#readinglist=='To Be Read' && percent ==#0
	then 'toberead' 

	elif percent >=#100
	then 'read' 

	elif percent == 'None'
	then 'undefined' 

	elif percent >=#0
	then 'unread' 

	fi

Last edited by ownedbycats; Yesterday at 10:15 PM.
ownedbycats is offline   Reply With Quote
Old Yesterday, 10:50 PM   #8
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,891
Karma: 7036723
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by foosion View Post
I'd like to create something that goes through all of my Calibre books, finds those that have the onkobo column checked but doesn't have a date in the finished column, then choose one at random.

Something like:

Code:
import random

unfinished = [book for books if book.onkobo and not book.finished]
book = random.choice(unfinished)
show(book.title, book.author)
How would I do this?
Create a VL with the search expression you wish then use the built-in "Pick a random book" action.

You would probably also want to do one or both of:
  • add the "Pick..." action to some toolbar or context menu.
  • add the "All GUI actions" action somewhere, which gives you access to all actions without putting them on menus etc individually. This action an excellent way to see calibre actions that are hidden by default.

Edit: If your goal is to read (View) the random book, do it in Action chains.
  • Choose the virtual library.
  • Pick a random book.
  • View that book.
  • Turn off the chosen VL.

EDIT 2: My post is more-or-less the same as @theduck's post (#2 above). Apologies for the repeat.

Last edited by chaley; Today at 03:33 AM.
chaley is offline   Reply With Quote
Old Today, 03:38 AM   #9
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,891
Karma: 7036723
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
@foosion: if you really want to roll your own implementation, I think the easiest is to do it in an Action chains python action. Use db.cache.search() to get the list of ids, select one randomly, then gui2.actions.view.view_format_by_id() to launch the viewer.

Last edited by chaley; Today at 05:55 AM. Reason: spelling
chaley is offline   Reply With Quote
Old Today, 05:54 AM   #10
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,891
Karma: 7036723
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Here is a sample Action chains python action that does a search, selects a random book id, then "view"s the EPUB format of that book.

Code:
def run(gui, settings, chain):
	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)
chaley is offline   Reply With Quote
Old Today, 06:04 AM   #11
foosion
Groupie
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: 189
Karma: 4562
Join Date: Sep 2011
Device: Kobo Libra 2 & Clara BW
Although I've been using Calibre for about 15 years, until I got a Kobo I barely used any of Calibre's features beyond add a book and view. I'm going to have to devote some time to reading the manual and playing.

foosion is offline   Reply With Quote
Old Today, 06:22 AM   #12
foosion
Groupie
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: 189
Karma: 4562
Join Date: Sep 2011
Device: Kobo Libra 2 & Clara BW
Quote:
Originally Posted by chaley View Post
Here is a sample Action chains python action that does a search, selects a random book id, then "view"s the EPUB format of that book.

Code:
def run(gui, settings, chain):
	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)
That is very powerful. I need to learn the Calibre API.

I'd do "#onkobo:true and #finished:false" instead of #mybool.

Is there a way to show a message, if I want to identify the chosen book rather than use the viewer?
foosion is offline   Reply With Quote
Old Today, 06:24 AM   #13
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,891
Karma: 7036723
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by foosion View Post
Is there a way to show a message, if I want to identify the chosen book rather than use the viewer?
What exactly do you want to do? Display a dialog? Select the book in the book list? Something else?
chaley is offline   Reply With Quote
Old Today, 06:27 AM   #14
foosion
Groupie
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: 189
Karma: 4562
Join Date: Sep 2011
Device: Kobo Libra 2 & Clara BW
Quote:
Originally Posted by chaley View Post
What exactly do you want to do? Display a dialog? Select the book in the book list? Something else?
Identify the chosen book. Highlighting it or popping up a message box.
foosion is offline   Reply With Quote
Old Today, 06:28 AM   #15
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,891
Karma: 7036723
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by foosion View Post
Identify the chosen book. Highlighting it or popping up a message box.
Which one of those two? They are implemented very differently.
chaley 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 01:36 PM.


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