View Single Post
Old 01-14-2025, 02:03 PM   #1413
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,199
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
The event naturally fires every time book(s) are added and selects those books exclusively. Does not make sense for it to select books that were added an hour ago, at which time the event fired for these books.

Seems like you want to do is more suited for a timer event that executes a chain periodically at a configurable time intervals.

Whichever way you choose to go, here is a python template that should work with the "Search using template" action, it will select books added in the last hour, you can edit the code (the part highlighted in red), to your liking.

Code:
python:
def evaluate(book, context):
    from calibre.utils.date import now
    book_ids = ''
    db = context.db
    current = now()
    for book_id in db.data.search_getting_ids('date:today', ''):
        dt = db.new_api.field_for('timestamp',book_id)
        delta = current - dt
        if delta.total_seconds() < 60 * 60:
            book_ids += f'{book_id},'
    return book_ids.strip(',')
Now, in the settings of the action make sure to do the following:
  • Tick the option "search result is book ids"
  • Tick the checkbox "Select books"

Last edited by capink; 01-14-2025 at 02:07 PM.
capink is offline   Reply With Quote