Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 12-01-2023, 02:07 PM   #1201
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,130
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
Action Chains does not have actions that can read from text files, it also does not have actions correlating to the newly introduced notes functions. What you want to do can be achieved using few python lines, which can be done using Action Chains since it provides a run python code action.

Attached below is a chain that should do what you want. To import it: Action Chains > Add/modify chains > right click table > import > choose the attached zip file. Now you should see a menu entry under Actions Chains for the newly created chain.

Few notes however:
  • This action makes the assumption, based on what you wrote in your post, that the TXT files will be in books that have series index = 9999999.
  • I did not include the delete action in the chain, since it is a destructive action, it is better left to you once you've tested the solution and are satisfied with it. To delete all the old notes, simply type the following search in calibre search:
    Code:
    series_index:=9999999
    Now choose all the books and delete them, or if you only want to delete only the TXT format their is an option in calibre to choose what format you want to delete.
  • Goes without saying that you have to make a backup for your calibre library before proceeding with any of this, until you are sure the solution is satisfactory.
Attached Files
File Type: zip move_notes.zip (730 Bytes, 79 views)
capink is offline   Reply With Quote
Old 12-06-2023, 02:00 PM   #1202
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,047
Karma: 62040591
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Is it possible to have a 'wait for user', where the user needs to confirm before the chain continues?

Use-case for this would be the plugins that use self.gui.proceed_question() like Check ISBN or FanFicFare downloads, which aren't easy for AC to detect and often result in other actions firing off before the user can confirm the library changes. (This was talked about before, but there wasn't really a good solution except 'disable the confirmations if possible.')

I tried 'prompt for confirmation' but that locked off the rest of the UI, lol.

Last edited by ownedbycats; 12-06-2023 at 02:07 PM.
ownedbycats is offline   Reply With Quote
Advert
Old 12-06-2023, 04:34 PM   #1203
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,130
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
We've been over this before, and there is no way to block proceed_question() type of actions. You can go back and read the posts we've exchanged back then. If someone wants to give this a go, patches are welcome.

The only solution to this issue to consider actions that use proceed_question not compatible with Action Chains and stop using them inside the plugin.
capink is offline   Reply With Quote
Old 12-09-2023, 02:24 PM   #1204
terry.nz
Junior Member
terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.
 
Posts: 9
Karma: 1466
Join Date: May 2016
Location: Canterbury, New Zealand
Device: Kobo Glo
After posting I went on to try PMC (Pulovers Macro Creator) but that proved troublesome, so currently heading the AutoHotKey v2 route. I thank you for providing some code (which I don't understand full) but upon trying I got this error ( I don't expect you to fix it as I do want to try my idea with AHK):

calibre, version 7.1.0
ERROR: Unhandled exception: <b>UnicodeDecodeError</b>:'utf-8' codec can't decode byte 0xdc in position 214: invalid continuation byte

calibre 7.1 embedded-python: True
Windows-10-10.0.19045-SP0 Windows ('64bit', 'WindowsPE')
('Windows', '10', '10.0.19045')
Python 3.11.5
Windows: ('10', '10.0.19045', 'SP0', 'Multiprocessor Free')
Interface language: None
Successfully initialized third party plugins: Action Chains (1, 18, 19) && DOC Input (1, 0, 1) && Editor Chains (0, 9, 6) && Find Duplicates (1, 10, 8) && Import List (1, 9, 1) && Kobo Books (1, 9, 2) && Kobo Utilities (2, 16, 12) && KoboTouchExtended (3, 6, 7) && Modify ePub (1, 8, 2) && Quality Check (1, 13, 6) && Resize Cover (1, 2, 0)
Traceback (most recent call last):
File "calibre_plugins.action_chains.action", line 451, in run_chain
File "calibre_plugins.action_chains.chains", line 403, in run
File "calibre_plugins.action_chains.chains", line 208, in _run_loop
File "calibre_plugins.action_chains.chains", line 181, in _run_loop
File "calibre_plugins.action_chains.actions.code", line 174, in run
File "module", line 18, in run
File "codecs.py", line 322, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdc in position 214: invalid continuation byte
terry.nz is offline   Reply With Quote
Old 12-09-2023, 04:04 PM   #1205
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,130
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
That means the note text files have an encoding that is not 'utf8'. You have to figure out that encoding your text editor save with, which depends on what language you are using for these, and add the proper encoding as follows (added bit are highlighted in red):
Code:
import regex

fmt = 'TXT'

def run(gui, settings, chain):
    #db = DB(library_path)
    db = gui.current_db
    book_ids = db.data.search_getting_ids('series_index:=9999999', None)
    for book_id in book_ids:
        path_to_book = db.format_abspath(book_id, fmt, index_is_id=True)
        title = db.title(book_id, index_is_id=True)
        series_name = db.new_api.field_for('series', book_id)
        print(f'Book title: {title} | Series: {series_name}')
        if not path_to_book:
            print(f'Book does not have format: {fmt}')
            continue
        with open(path_to_book, 'r', encoding='insert_proper_encoding_here') as f:
            note = regex.sub(r'http[^\s]+', r'', f.read())
            series_id = db.new_api.get_item_id('series', series_name)
            print(f'series_id: {series_id} | note: {note}')
            db.new_api.set_notes_for('series', series_id, note)
capink is offline   Reply With Quote
Advert
Old 12-09-2023, 04:30 PM   #1206
terry.nz
Junior Member
terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.
 
Posts: 9
Karma: 1466
Join Date: May 2016
Location: Canterbury, New Zealand
Device: Kobo Glo
I was about to reply that the TXT files are UTF-8 as I spot checked some using Notepad++ which is generally pretty good identifying the encoding type. Then the last one I spot checked came back as ANSI. So it would seem that somehow there are possibly a few incorrectly encoded TXT files. I've no idea how that may have occured, but with 970 of them to check it's going to be a mission to sort out.

Thanks
Terry
terry.nz is offline   Reply With Quote
Old 12-09-2023, 04:45 PM   #1207
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,047
Karma: 62040591
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Quote:
Originally Posted by terry.nz View Post
I was about to reply that the TXT files are UTF-8 as I spot checked some using Notepad++ which is generally pretty good identifying the encoding type. Then the last one I spot checked came back as ANSI. So it would seem that somehow there are possibly a few incorrectly encoded TXT files. I've no idea how that may have occured, but with 970 of them to check it's going to be a mission to sort out.

Thanks
Terry
Since you're on Windows, I've used this in past: https://web.archive.org/web/20181121...ncodingchecker

Last edited by ownedbycats; 12-09-2023 at 04:56 PM.
ownedbycats is offline   Reply With Quote
Old 12-09-2023, 05:02 PM   #1208
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,130
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by terry.nz View Post
I was about to reply that the TXT files are UTF-8 as I spot checked some using Notepad++ which is generally pretty good identifying the encoding type. Then the last one I spot checked came back as ANSI. So it would seem that somehow there are possibly a few incorrectly encoded TXT files. I've no idea how that may have occured, but with 970 of them to check it's going to be a mission to sort out.

Thanks
Terry
You can run this code below instead, which will automatically try ansi if utf-8 fails:

Code:
import regex

fmt = 'TXT'

encodings = ['utf-8','windows-1252']

def move_note(db, book_id, encoding='utf-8'):
    path_to_book = db.format_abspath(book_id, fmt, index_is_id=True)
    title = db.title(book_id, index_is_id=True)
    series_name = db.new_api.field_for('series', book_id)
    print(f'Book title: {title} | Series: {series_name}')
    if not path_to_book:
        print(f'Book does not have format: {fmt}')
        return
    with open(path_to_book, 'r', encoding=encoding) as f:
        note = regex.sub(r'http[^\s]+', r'', f.read())
        series_id = db.new_api.get_item_id('series', series_name)
        print(f'series_id: {series_id} | note: {note}')
        db.new_api.set_notes_for('series', series_id, note)

def run(gui, settings, chain):
    db = gui.current_db
    book_ids = db.data.search_getting_ids('series_index:=9999999', None)
    failed_ids = []
    for book_id in book_ids:
        for encoding in encodings:
            print(f'call move_notes for {book_id} with encoding {encoding}')
            try:
                move_note(db, book_id, encoding=encoding)
                break
            except:
                print(f'Encoding {encoding} failed for book {book_id}')
Note: You can add other encoding to the list of encodings highlighted in red.
capink is offline   Reply With Quote
Old 12-09-2023, 07:13 PM   #1209
terry.nz
Junior Member
terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.
 
Posts: 9
Karma: 1466
Join Date: May 2016
Location: Canterbury, New Zealand
Device: Kobo Glo
I used an encoder checker (from github, maybe a fork of the one mentioned above) which checked and re-encoded those that weren't utf-8. Unfortunately the Pyton code still manages to find a badly encoded file. I then went in search of the badly encoded file using the series information (it seems that the process was running through the series in alhabetical order).

I spotted another issue and it possibly also stems from the TXT file contents. The TXT file has normal line endings (CR & LF) but after the pyton code has transferred that content to the series notes the CR and LF have been removed and everything is essentially on 1 line.

Thanks everyone, but at this point I think I'd rather spend a bit more time with AHK. It will be a good learning curve for me as well and allow me to expand on other fronts at a later stage.

Terry
terry.nz is offline   Reply With Quote
Old 12-23-2023, 10:56 PM   #1210
terry.nz
Junior Member
terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.terry.nz is no ebook tyro.
 
Posts: 9
Karma: 1466
Join Date: May 2016
Location: Canterbury, New Zealand
Device: Kobo Glo
Well good news, AHK finally came through. I did find the worst problem in running my code was having to add in sleep commands after every line of code, otherwise the code just ran too fast for each window to appear or for a paste from clipboard (especially for the larger data sets). Learning the actual AHK code wasn't to bad.

As I finish this post my code is also finishing off the 980 or so TXT files conversions to serial notes.

Terry
terry.nz is offline   Reply With Quote
Old 12-31-2023, 02:36 PM   #1211
shinykari
Member
shinykari doesn't littershinykari doesn't litter
 
Posts: 21
Karma: 128
Join Date: Jan 2020
Device: Kobo Libre2
Is there a way to update a column only if the current value is blank? I would like to set the "kobo_read_date" to the current date, but only if the "kobo_read_date" is currently empty.
shinykari is offline   Reply With Quote
Old 12-31-2023, 02:42 PM   #1212
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,130
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by shinykari View Post
Is there a way to update a column only if the current value is blank? I would like to set the "kobo_read_date" to the current date, but only if the "kobo_read_date" is currently empty.
Yes, you can do this directly in calibre without using Action Chains:
  1. Filter out the books that have blank value using the following search:
    Code:
    #kobo_read_date:false
  2. Select all the books resulting from the previous search, and then use calibre metadata edit to set the kobo_read_date to current date by pressing the "today" button next to the kobo_read_date cell in the bulk metadata edit dialog.

If you still want to do this using the plugin, you use the search above as the scope for a single field edit action that sets the date to current time.
capink is offline   Reply With Quote
Old 12-31-2023, 03:38 PM   #1213
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,047
Karma: 62040591
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Quote:
Originally Posted by shinykari View Post
Is there a way to update a column only if the current value is blank? I would like to set the "kobo_read_date" to the current date, but only if the "kobo_read_date" is currently empty.
You can use a single-field edit with this template:

Code:
program:

	if 
		$#kobo_read_date
	then 
		$$#kobo_read_date
	else 
		today() 
	fi
This checks whether #kobo_read_date is populated. If so, it'll return its value and remain unchanged. If it's not populated, it instead returns current datetime.
ownedbycats is offline   Reply With Quote
Old 12-31-2023, 06:44 PM   #1214
shinykari
Member
shinykari doesn't littershinykari doesn't litter
 
Posts: 21
Karma: 128
Join Date: Jan 2020
Device: Kobo Libre2
Thank you both! I knew I could do it manually with searching, but I've set up a few multi-action chains that I'd like to add this onto, so the program template will be super useful.
shinykari is offline   Reply With Quote
Old 01-09-2024, 11:31 PM   #1215
nqk
Fanatic
nqk does all things with Zen-like beautynqk does all things with Zen-like beautynqk does all things with Zen-like beautynqk does all things with Zen-like beautynqk does all things with Zen-like beautynqk does all things with Zen-like beautynqk does all things with Zen-like beautynqk does all things with Zen-like beautynqk does all things with Zen-like beautynqk does all things with Zen-like beautynqk does all things with Zen-like beauty
 
Posts: 517
Karma: 32106
Join Date: Feb 2012
Device: Onyx Boox Leaf
I want to extract a certain file from the txtz file to certain folder. I create this cmd file with only one line, and it works (drag and drop or open-with in Windows Exlorer)

Code:
"C:\Program Files\7-Zip\7z.exe" e %1 -o"D:\Temp" file-to-extract -y
However, the "Open with" action in this Plugin (with binarypath being the path to the cmd file) doesn't do anything.

Please help me to config the ActionChain to make it work.

At present, my work around is
1) In Windows, set the cmd file as "default app" to open txtz file (which I don't really like)
2) In Acction Chain, use "Open with default app".

This is not a good solution, I think.

Last edited by nqk; 01-10-2024 at 01:45 AM.
nqk is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Editor Plugin] Editor Chains capink Plugins 94 07-03-2024 07:26 PM
Action Chains Resources capink Plugins 65 07-01-2024 03:12 PM
[GUI Plugin] Noosfere_util, a companion plugin to noosfere DB lrpirlet Plugins 2 08-18-2022 03:15 PM
[GUI Plugin] Save Virtual Libraries To Column (GUI) chaley Plugins 14 04-04-2021 05:25 AM


All times are GMT -4. The time now is 01:59 AM.


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