def upgrade_version_19(self): recipes = self.db.get('SELECT id,title,script FROM feeds') if recipes: from calibre.web.feeds.recipes import (custom_recipes, custom_recipe_filename) bdir = os.path.dirname(custom_recipes.file_path) for id_, title, script in recipes: existing = frozenset(map(int, custom_recipes.iterkeys())) if id_ in existing: id_ = max(existing) + 1000 id_ = str(id_) fname = custom_recipe_filename(id_, title) custom_recipes[id_] = (title, fname) if isinstance(script, unicode): script = script.encode('utf-8') with open(os.path.join(bdir, fname), 'wb') as f: f.write(script)
def add_custom_recipe(title, script): 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 id_ = str(id_) bdir = os.path.dirname(custom_recipes.file_path) fname = custom_recipe_filename(id_, title) if isinstance(script, unicode): script = script.encode('utf-8') custom_recipes[id_] = (title, fname) with open(os.path.join(bdir, fname), 'wb') as f: f.write(script)
def update_custom_recipe(id_, title, script): from calibre.web.feeds.recipes import custom_recipes, \ custom_recipe_filename id_ = str(int(id_)) existing = custom_recipes.get(id_, None) bdir = os.path.dirname(custom_recipes.file_path) if existing is None: fname = custom_recipe_filename(id_, title) else: fname = existing[1] if isinstance(script, unicode): script = script.encode('utf-8') custom_recipes[id_] = (title, fname) 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 bdir = os.path.dirname(custom_recipes.file_path) with custom_recipes: for title, script in script_map.iteritems(): fid = str(id_) fname = custom_recipe_filename(fid, title) if isinstance(script, unicode): script = script.encode('utf-8') custom_recipes[fid] = (title, fname) if not os.path.exists(bdir): os.makedirs(bdir) with open(os.path.join(bdir, fname), 'wb') as f: f.write(script) id_ += 1
def update_custom_recipes(script_ids): from calibre.web.feeds.recipes import custom_recipes, \ custom_recipe_filename bdir = os.path.dirname(custom_recipes.file_path) for id_, title, script in script_ids: id_ = unicode_type(int(id_)) existing = custom_recipes.get(id_, None) if existing is None: fname = custom_recipe_filename(id_, title) else: fname = existing[1] if isinstance(script, unicode_type): script = script.encode('utf-8') custom_recipes[id_] = (title, fname) if not os.path.exists(bdir): os.makedirs(bdir) 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 bdir = os.path.dirname(custom_recipes.file_path) with custom_recipes: for title, script in script_map.iteritems(): fid = str(id_) fname = custom_recipe_filename(fid, title) if isinstance(script, unicode): script = script.encode('utf-8') custom_recipes[fid] = (title, fname) if not os.path.exists(bdir): os.makedirs(bdir) with open(os.path.join(bdir, fname), 'wb') as f: f.write(script) id_ += 1