Download builtin recipes from GUI as well as from CLI

This commit is contained in:
Kovid Goyal 2009-12-13 14:55:25 -07:00
parent 0d152c41dd
commit 00a9d8bd16
2 changed files with 14 additions and 5 deletions

View File

@ -92,7 +92,7 @@ def get_builtin_recipe_titles():
def download_builtin_recipe(urn): def download_builtin_recipe(urn):
br = browser() br = browser()
return br.open('http://status.calibre-ebook.com/recipe/'+urn).read() return br.open_novisit('http://status.calibre-ebook.com/recipe/'+urn).read()
def get_builtin_recipe_by_title(title, log=None, download_recipe=False): def get_builtin_recipe_by_title(title, log=None, download_recipe=False):

View File

@ -16,7 +16,7 @@ from calibre.gui2 import NONE
from calibre.utils.localization import get_language from calibre.utils.localization import get_language
from calibre.web.feeds.recipes.collection import \ from calibre.web.feeds.recipes.collection import \
get_builtin_recipe_collection, get_custom_recipe_collection, \ get_builtin_recipe_collection, get_custom_recipe_collection, \
SchedulerConfig SchedulerConfig, download_builtin_recipe
from calibre.utils.pyparsing import ParseException from calibre.utils.pyparsing import ParseException
class NewsTreeItem(object): class NewsTreeItem(object):
@ -129,13 +129,22 @@ class RecipeModel(QAbstractItemModel, SearchQueryParser):
self.scheduler_config = SchedulerConfig() self.scheduler_config = SchedulerConfig()
self.do_refresh() self.do_refresh()
def get_recipe(self, urn): def get_builtin_recipe(self, urn, download=True):
if download:
try:
return download_builtin_recipe(urn)
except:
import traceback
traceback.print_exc()
return P('recipes/%s.recipe'%urn, data=True)
def get_recipe(self, urn, download=True):
coll = self.custom_recipe_collection if urn.startswith('custom:') \ coll = self.custom_recipe_collection if urn.startswith('custom:') \
else self.builtin_recipe_collection else self.builtin_recipe_collection
for recipe in coll: for recipe in coll:
if recipe.get('id', False) == urn: if recipe.get('id', False) == urn:
if coll is self.builtin_recipe_collection: if coll is self.builtin_recipe_collection:
return P('recipes/%s.recipe'%urn[8:], data=True) return self.get_builtin_recipe(urn[8:], download=download)
return self.db.get_feed(int(urn[len('custom:'):])) return self.db.get_feed(int(urn[len('custom:'):]))
def update_custom_recipe(self, urn, title, script): def update_custom_recipe(self, urn, title, script):
@ -332,7 +341,7 @@ class RecipeModel(QAbstractItemModel, SearchQueryParser):
def get_to_be_downloaded_recipes(self): def get_to_be_downloaded_recipes(self):
ans = self.scheduler_config.get_to_be_downloaded_recipes() ans = self.scheduler_config.get_to_be_downloaded_recipes()
ans2 = [x for x in ans if self.get_recipe(x) is not None] ans2 = [x for x in ans if self.get_recipe(x, download=False) is not None]
for x in set(ans) - set(ans2): for x in set(ans) - set(ans2):
self.un_schedule_recipe(x) self.un_schedule_recipe(x)
return ans2 return ans2