![]() |
#1201 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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:
|
![]() |
![]() |
![]() |
#1202 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
Advert | |
|
![]() |
#1203 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#1204 |
Junior Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 |
![]() |
![]() |
![]() |
#1205 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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)
|
![]() |
![]() |
Advert | |
|
![]() |
#1206 |
Junior Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 |
![]() |
![]() |
![]() |
#1207 | |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,047
Karma: 62040591
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Quote:
Last edited by ownedbycats; 12-09-2023 at 04:56 PM. |
|
![]() |
![]() |
![]() |
#1208 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,130
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
|
Quote:
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}')
|
|
![]() |
![]() |
![]() |
#1209 |
Junior Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 |
![]() |
![]() |
![]() |
#1210 |
Junior Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 |
![]() |
![]() |
![]() |
#1211 |
Member
![]() ![]() 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.
|
![]() |
![]() |
![]() |
#1212 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,130
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
|
Quote:
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. |
|
![]() |
![]() |
![]() |
#1213 | |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,047
Karma: 62040591
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Quote:
Code:
program: if $#kobo_read_date then $$#kobo_read_date else today() fi |
|
![]() |
![]() |
![]() |
#1214 |
Member
![]() ![]() 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.
|
![]() |
![]() |
![]() |
#1215 |
Fanatic
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 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. |
![]() |
![]() |
![]() |
|
![]() |
||||
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 |