View Single Post
Old 11-26-2014, 09:08 PM   #16
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
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.

Last edited by eschwartz; 11-26-2014 at 09:15 PM.
eschwartz is offline   Reply With Quote