View Single Post
Old 11-27-2014, 05:01 AM   #18
Josieb1
Grand Sorcerer
Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.
 
Posts: 5,090
Karma: 18051062
Join Date: Nov 2009
Location: UK
Device: Kindle Scribe, Coloursoft, PW SE, Kindle 6, Kobo Libra 2, Clara BW
Quote:
Originally Posted by eschwartz View Post
I figured something out.

Save this code as a file, "calibre-add-format-blank-txt.py".

But first, see the bit in red? Change that to 'C:\\Users\Josieb1\\Calibre Library\\' or wherever your library is located, and make sure there are two backslashes.

Then run the following command in the command prompt:

Code:
calibre-debug.exe C:\path\to\wherever\you\put\calibre-add-format-blank-txt.py
Here is the code.
Code:
def init_cache(library_path):
        from calibre.db.backend import DB
        from calibre.db.cache import Cache
        backend = DB(library_path)
        cache = Cache(backend)
        cache.init()
        return cache

import tempfile
temporary_txt_file = tempfile.NamedTemporaryFile(suffix='txt', delete=False)

cache = init_cache(library_path = 'C:\\Users\\<username>\\Calibre Library\\')


for id in cache.all_book_ids():
        cache.add_format(id, 'TXT', temporary_txt_file)
P.S. chaley, thanks for the similar python script you created in the templates, plugboards, custom columns thread a while back, you helped me figure out how to interface with calibre.
Does this look good?


I decided it wasn't worth trying to deal with json on other peoples' machines especially Windows, so it's all native calibre code.

Tested on a test library of mine, on a Win7 machine.
Thank you so much

I had a few problems getting the path right but eventually I got the message Welcome to the Interactive Calibre Shell. Does that mean its working?

I have nearly 6000 books so I don't know how long to leave it before I check in Calibre.

Last edited by Josieb1; 11-27-2014 at 05:05 AM.
Josieb1 is offline   Reply With Quote