mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-08 21:04:45 +02:00
A method to add many custom recipes at once
This commit is contained in:
parent
9d19b182de
commit
6197920256
1 changed files with 21 additions and 0 deletions
|
|
@ -158,6 +158,27 @@ def add_custom_recipe(title, script):
|
|||
with open(os.path.join(bdir, fname), 'wb') as f:
|
||||
f.write(script)
|
||||
|
||||
def add_custom_recipes(script_map):
|
||||
from calibre.web.feeds.recipes import custom_recipes, \
|
||||
custom_recipe_filename
|
||||
id_ = 1000
|
||||
keys = tuple(map(int, custom_recipes.iterkeys()))
|
||||
if keys:
|
||||
id_ = max(keys)+1
|
||||
with custom_recipes:
|
||||
for title, script in script_map.iteritems():
|
||||
fid = str(id_)
|
||||
bdir = os.path.dirname(custom_recipes.file_path)
|
||||
|
||||
fname = custom_recipe_filename(fid, title)
|
||||
if isinstance(script, unicode):
|
||||
script = script.encode('utf-8')
|
||||
|
||||
custom_recipes[fid] = (title, fname)
|
||||
|
||||
with open(os.path.join(bdir, fname), 'wb') as f:
|
||||
f.write(script)
|
||||
|
||||
|
||||
def remove_custom_recipe(id_):
|
||||
from calibre.web.feeds.recipes import custom_recipes
|
||||
|
|
|
|||
Loading…
Reference in a new issue