当前位置: 首页>>代码示例>>Python>>正文


Python FormatterError.bulletinBuilderFormatterError方法代码示例

本文整理汇总了Python中superdesk.errors.FormatterError.bulletinBuilderFormatterError方法的典型用法代码示例。如果您正苦于以下问题:Python FormatterError.bulletinBuilderFormatterError方法的具体用法?Python FormatterError.bulletinBuilderFormatterError怎么用?Python FormatterError.bulletinBuilderFormatterError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在superdesk.errors.FormatterError的用法示例。


在下文中一共展示了FormatterError.bulletinBuilderFormatterError方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: format

# 需要导入模块: from superdesk.errors import FormatterError [as 别名]
# 或者: from superdesk.errors.FormatterError import bulletinBuilderFormatterError [as 别名]
    def format(self, article, subscriber):
        """
        Formats the article as require by the subscriber
        :param dict article: article to be formatted
        :param dict subscriber: subscriber receiving the article
        :return: tuple (int, str) of publish sequence of the subscriber, formatted article as string
        """
        try:
            pub_seq_num = superdesk.get_resource_service('subscribers').generate_sequence_number(subscriber)
            body_html = article.get('body_html', '').strip('\r\n')
            soup = BeautifulSoup(body_html)
            for br in soup.find_all('br'):
                # remove the <br> tag
                br.replace_with(' {}'.format(br.get_text()))

            for p in soup.find_all('p'):
                # replace <p> tag with two carriage return
                p.replace_with('{}\r\n\r\n'.format(p.get_text()))

            article['body_text'] = soup.get_text()

            # get the first category and derive the locator
            category = next((iter(article.get('anpa_category', []))), None)
            if category:
                locator = LocatorMapper().map(article, category.get('qcode').upper())
                if locator:
                    article['place'] = [{'qcode': locator, 'name': locator}]

            return [(pub_seq_num, superdesk.json.dumps(article, default=json_serialize_datetime_objectId))]
        except Exception as ex:
            raise FormatterError.bulletinBuilderFormatterError(ex, subscriber)
开发者ID:ancafarcas,项目名称:superdesk,代码行数:33,代码来源:aap_bulletinbuilder_formatter.py

示例2: format

# 需要导入模块: from superdesk.errors import FormatterError [as 别名]
# 或者: from superdesk.errors.FormatterError import bulletinBuilderFormatterError [as 别名]
    def format(self, article, subscriber):
        """
        Formats the article as require by the subscriber
        :param dict article: article to be formatted
        :param dict subscriber: subscriber receiving the article
        :return: tuple (int, str) of publish sequence of the subscriber, formatted article as string
        """
        try:

            article['slugline'] = self.append_legal(article=article, truncate=True)
            pub_seq_num = superdesk.get_resource_service('subscribers').generate_sequence_number(subscriber)
            body_html = self.append_body_footer(article).strip('\r\n')
            soup = BeautifulSoup(body_html, 'html.parser')

            if not len(soup.find_all('p')):
                for br in soup.find_all('br'):
                    # remove the <br> tag
                    br.replace_with(' {}'.format(br.get_text()))

            for p in soup.find_all('p'):
                # replace <p> tag with two carriage return
                for br in p.find_all('br'):
                    # remove the <br> tag
                    br.replace_with(' {}'.format(br.get_text()))

                para_text = p.get_text().strip()
                if para_text != '':
                    p.replace_with('{}\r\n\r\n'.format(para_text))
                else:
                    p.replace_with('')

            article['body_text'] = re.sub(' +', ' ', soup.get_text())
            # get the first category and derive the locator
            category = next((iter(article.get('anpa_category', []))), None)
            if category:
                locator = LocatorMapper().map(article, category.get('qcode').upper())
                if locator:
                    article['place'] = [{'qcode': locator, 'name': locator}]

                article['first_category'] = category
                article['first_subject'] = set_subject(category, article)

            odbc_item = {
                'id': article.get(config.ID_FIELD),
                'version': article.get(config.VERSION),
                ITEM_TYPE: article.get(ITEM_TYPE),
                PACKAGE_TYPE: article.get(PACKAGE_TYPE, ''),
                'headline': article.get('headline', '').replace('\'', '\'\''),
                'slugline': article.get('slugline', '').replace('\'', '\'\''),
                'data': superdesk.json.dumps(article, default=json_serialize_datetime_objectId).replace('\'', '\'\'')
            }

            return [(pub_seq_num, json.dumps(odbc_item, default=json_serialize_datetime_objectId))]
        except Exception as ex:
            raise FormatterError.bulletinBuilderFormatterError(ex, subscriber)
开发者ID:MiczFlor,项目名称:superdesk-core,代码行数:57,代码来源:aap_bulletinbuilder_formatter.py

示例3: format

# 需要导入模块: from superdesk.errors import FormatterError [as 别名]
# 或者: from superdesk.errors.FormatterError import bulletinBuilderFormatterError [as 别名]
    def format(self, article, subscriber):
        try:
            pub_seq_num = superdesk.get_resource_service("subscribers").generate_sequence_number(subscriber)
            body_html = article.get("body_html", "").strip("\r\n")
            soup = BeautifulSoup(body_html)
            for br in soup.find_all("br"):
                # remove the <br> tag
                br.replace_with(" {}".format(br.get_text()))

            for p in soup.find_all("p"):
                # replace <p> tag with two carriage return
                p.replace_with("{}\r\n\r\n".format(p.get_text()))

            article["body_text"] = soup.get_text()

            return [(pub_seq_num, superdesk.json.dumps(article, default=json_serialize_datetime_objectId))]
        except Exception as ex:
            raise FormatterError.bulletinBuilderFormatterError(ex, subscriber)
开发者ID:oxcarh,项目名称:superdesk,代码行数:20,代码来源:aap_bulletinbuilder_formatter.py

示例4: format

# 需要导入模块: from superdesk.errors import FormatterError [as 别名]
# 或者: from superdesk.errors.FormatterError import bulletinBuilderFormatterError [as 别名]
    def format(self, article, subscriber, codes=None):
        """
        Formats the article as require by the subscriber
        :param dict article: article to be formatted
        :param dict subscriber: subscriber receiving the article
        :param list codes: selector codes
        :return: tuple (int, str) of publish sequence of the subscriber, formatted article as string
        """
        try:
            formatted_article = deepcopy(article)

            pub_seq_num = superdesk.get_resource_service('subscribers').generate_sequence_number(subscriber)
            body_html = to_ascii(self.append_body_footer(formatted_article)).strip('\r\n')

            # get the desk name
            desk_name = superdesk.get_resource_service('desks').\
                get_desk_name(formatted_article.get('task', {}).get('desk'))

            # force the content to source 'NZN' if desk is 'NZN'
            if 'new zealand' in desk_name.lower().strip():
                formatted_article['source'] = 'NZN'

            # this is temporary fix for bulletin builder formatter
            if formatted_article.get(ITEM_STATE, '') == CONTENT_STATE.SCHEDULED:
                formatted_article['versioncreated'] = utcnow()

            formatted_article['body_text'] = self.get_text_content(body_html)
            formatted_article['abstract'] = self.get_text_content(
                to_ascii(formatted_article.get('abstract', '') or '')).strip()
            formatted_article['headline'] = self.get_text_content(
                to_ascii(formatted_article.get('headline', ''))).strip()
            formatted_article['byline'] = self.get_text_content(
                to_ascii(formatted_article.get('byline', '') or '')).strip()

            if len(formatted_article.get('anpa_category') or []) > 1:
                formatted_article['anpa_category'] = [cat for cat in (formatted_article.get('anpa_category') or [])
                                                      if cat.get('qcode') != 'c']

            self._handle_auto_publish(formatted_article)

            # get the first category and derive the locator
            category = next((iter((formatted_article.get('anpa_category') or []))), None)

            if category:
                locator = LocatorMapper().map(formatted_article, category.get('qcode').upper())
                if locator:
                    formatted_article['place'] = [{'qcode': locator, 'name': locator}]

                formatted_article['first_category'] = category
                formatted_article['first_subject'] = set_subject(category, formatted_article)
                formatted_article['slugline'] = self.get_text_content(
                    to_ascii(SluglineMapper().map(article=formatted_article,
                                                  category=category.get('qcode').upper(),
                                                  truncate=(not formatted_article.get('auto_publish')))).strip())

            self.format_associated_item(formatted_article)

            odbc_item = {
                'id': formatted_article.get(config.ID_FIELD),
                'version': formatted_article.get(config.VERSION),
                ITEM_TYPE: formatted_article.get(ITEM_TYPE),
                PACKAGE_TYPE: formatted_article.get(PACKAGE_TYPE, ''),
                'headline': formatted_article.get('headline', '').replace('\'', '\'\''),
                'slugline': formatted_article.get('slugline', '').replace('\'', '\'\''),
                'data': superdesk.json.dumps(formatted_article,
                                             default=json_serialize_datetime_objectId).replace('\'', '\'\'')
            }

            return [(pub_seq_num, json.dumps(odbc_item, default=json_serialize_datetime_objectId))]
        except Exception as ex:
            raise FormatterError.bulletinBuilderFormatterError(ex, subscriber)
开发者ID:akintolga,项目名称:superdesk-aap,代码行数:73,代码来源:aap_bulletinbuilder_formatter.py


注:本文中的superdesk.errors.FormatterError.bulletinBuilderFormatterError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。