コード例 #1
0
    def opml_import(self):
        from calibre.gui2.dialogs.opml import ImportOPML
        d = ImportOPML(parent=self)
        if d.exec_() != d.Accepted:
            return
        oldest_article, max_articles_per_feed, replace_existing = d.oldest_article, d.articles_per_feed, d.replace_existing
        failed_recipes, replace_recipes, add_recipes = {}, {}, {}

        for group in d.recipes:
            title = base_title = group.title or _('Unknown')
            if not replace_existing:
                c = 0
                while self._model.has_title(title):
                    c += 1
                    title = u'%s %d' % (base_title, c)
            src, title = self.options_to_profile(
                **{
                    'title': title,
                    'feeds': group.feeds,
                    'oldest_article': oldest_article,
                    'max_articles': max_articles_per_feed,
                })
            try:
                compile_recipe(src)
            except Exception:
                import traceback
                failed_recipes[title] = traceback.format_exc()
                continue

            if replace_existing and self._model.has_title(title):
                replace_recipes[title] = src
            else:
                add_recipes[title] = src

        if add_recipes:
            self.model.add_many(add_recipes)
        if replace_recipes:
            self.model.replace_many_by_title(replace_recipes)
        if failed_recipes:
            det_msg = '\n'.join('%s\n%s\n' % (title, tb)
                                for title, tb in failed_recipes.iteritems())
            error_dialog(
                self,
                _('Failed to create recipes'),
                _('Failed to create some recipes, click "Show details" for details'
                  ),
                show=True,
                det_msg=det_msg)
        self.clear()
コード例 #2
0
    def import_opml(self):
        from calibre.gui2.dialogs.opml import ImportOPML
        d = ImportOPML(parent=self)
        if d.exec_() != d.Accepted:
            return
        oldest_article, max_articles_per_feed, replace_existing = d.oldest_article, d.articles_per_feed, d.replace_existing
        failed_recipes, replace_recipes, add_recipes = {}, {}, {}

        for group in d.recipes:
            title = base_title = group.title or _('Unknown')
            if not replace_existing:
                c = 0
                while self.recipe_list.has_title(title):
                    c += 1
                    title = '%s %d' % (base_title, c)
            try:
                src = options_to_recipe_source(title, oldest_article,
                                               max_articles_per_feed,
                                               group.feeds)
                compile_recipe(src)
            except Exception:
                import traceback
                failed_recipes[title] = traceback.format_exc()
                continue

            if replace_existing and self.recipe_list.has_title(title):
                replace_recipes[title] = src
            else:
                add_recipes[title] = src

        if add_recipes:
            self.recipe_list.add_many(add_recipes)
        if replace_recipes:
            self.recipe_list.replace_many_by_title(replace_recipes)
        if failed_recipes:
            det_msg = '\n'.join('%s\n%s\n' % (title, tb)
                                for title, tb in iteritems(failed_recipes))
            error_dialog(
                self,
                _('Failed to create recipes'),
                _('Failed to create some recipes, click "Show details" for details'
                  ),
                show=True,
                det_msg=det_msg)
コード例 #3
0
ファイル: user_profiles.py プロジェクト: AtulKumar2/calibre
    def opml_import(self):
        from calibre.gui2.dialogs.opml import ImportOPML
        d = ImportOPML(parent=self)
        if d.exec_() != d.Accepted:
            return
        oldest_article, max_articles_per_feed, replace_existing = d.oldest_article, d.articles_per_feed, d.replace_existing
        failed_recipes, replace_recipes, add_recipes = {}, {}, {}

        for group in d.recipes:
            title = base_title = group.title or _('Unknown')
            if not replace_existing:
                c = 0
                while self._model.has_title(title):
                    c += 1
                    title = u'%s %d' % (base_title, c)
            src, title = self.options_to_profile(**{
                    'title':title,
                    'feeds':group.feeds,
                    'oldest_article':oldest_article,
                    'max_articles':max_articles_per_feed,
                })
            try:
                compile_recipe(src)
            except Exception:
                import traceback
                failed_recipes[title] = traceback.format_exc()
                continue

            if replace_existing and self._model.has_title(title):
                replace_recipes[title] = src
            else:
                add_recipes[title] = src

        if add_recipes:
            self.model.add_many(add_recipes)
        if replace_recipes:
            self.model.replace_many_by_title(replace_recipes)
        if failed_recipes:
            det_msg = '\n'.join('%s\n%s\n' % (title, tb) for title, tb in failed_recipes.iteritems())
            error_dialog(self, _('Failed to create recipes'), _(
                'Failed to create some recipes, click "Show details" for details'), show=True,
                         det_msg=det_msg)
        self.clear()
コード例 #4
0
ファイル: custom_recipes.py プロジェクト: JimmXinu/calibre
    def import_opml(self):
        from calibre.gui2.dialogs.opml import ImportOPML
        d = ImportOPML(parent=self)
        if d.exec_() != d.Accepted:
            return
        oldest_article, max_articles_per_feed, replace_existing = d.oldest_article, d.articles_per_feed, d.replace_existing
        failed_recipes, replace_recipes, add_recipes = {}, {}, {}

        for group in d.recipes:
            title = base_title = group.title or _('Unknown')
            if not replace_existing:
                c = 0
                while self.recipe_list.has_title(title):
                    c += 1
                    title = '%s %d' % (base_title, c)
            try:
                src = options_to_recipe_source(title, oldest_article, max_articles_per_feed, group.feeds)
                compile_recipe(src)
            except Exception:
                import traceback
                failed_recipes[title] = traceback.format_exc()
                continue

            if replace_existing and self.recipe_list.has_title(title):
                replace_recipes[title] = src
            else:
                add_recipes[title] = src

        if add_recipes:
            self.recipe_list.add_many(add_recipes)
        if replace_recipes:
            self.recipe_list.replace_many_by_title(replace_recipes)
        if failed_recipes:
            det_msg = '\n'.join('%s\n%s\n' % (title, tb) for title, tb in iteritems(failed_recipes))
            error_dialog(self, _('Failed to create recipes'), _(
                'Failed to create some recipes, click "Show details" for details'), show=True,
                         det_msg=det_msg)