Esempio n. 1
0
    def format(self, article, subscriber, codes=None):
        """
        Create article in Belga NewsML 1.2 format

        :param dict article:
        :param dict subscriber:
        :param list codes:
        :return [(int, str)]: return a List of tuples. A tuple consist of
            publish sequence number and formatted article string.
        :raises FormatterError: if the formatter fails to format an article
        """

        try:
            pub_seq_num = superdesk.get_resource_service(
                'subscribers').generate_sequence_number(subscriber)
            self._newsml = etree.Element('NewsML')
            self._article = article
            self._now = utcnow()
            self._string_now = self._now.strftime(self.DATETIME_FORMAT)
            # SD does not have the same structure, there are no packages,
            # but to cover old belga's news ml 1.2 output, this value will be used:
            self._package_duid = 'pkg_{}'.format(self._article[GUID_FIELD])

            self._format_catalog()
            self._format_newsenvelope()
            self._format_newsitem()

            xml_string = self.XML_ROOT + '\n' + etree.tostring(
                self._newsml, pretty_print=True).decode('utf-8')

            return [(pub_seq_num, xml_string)]
        except Exception as ex:
            raise FormatterError.newml12FormatterError(ex, subscriber)
Esempio n. 2
0
    def format(self, article, subscriber, codes=None):
        """
        Create article in NewsML1.2 format

        :param dict article:
        :param dict subscriber:
        :param list codes:
        :return [(int, str)]: return a List of tuples. A tuple consist of
            publish sequence number and formatted article string.
        :raises FormatterError: if the formatter fails to format an article
        """
        try:
            formatted_article = deepcopy(article)
            pub_seq_num = superdesk.get_resource_service(
                'subscribers').generate_sequence_number(subscriber)

            newsml = etree.Element("NewsML", {'Version': '1.2'})
            SubElement(
                newsml, "Catalog", {
                    'Href':
                    'http://about.reuters.com/newsml/vocabulary/catalog-reuters-3rdParty-master_catalog.xml'
                })
            news_envelope = SubElement(newsml, "NewsEnvelope")
            news_item = SubElement(newsml, "NewsItem")

            self._format_news_envelope(formatted_article, news_envelope,
                                       pub_seq_num)
            self._format_identification(formatted_article, news_item)
            self._format_news_management(formatted_article, news_item)
            self._format_news_component(formatted_article, news_item)

            return [(pub_seq_num,
                     self.XML_ROOT + etree.tostring(newsml).decode('utf-8'))]
        except Exception as ex:
            raise FormatterError.newml12FormatterError(ex, subscriber)
    def format(self, article, subscriber):
        """
        Create article in NewsML1.2 format
        :param dict article:
        :param dict subscriber:
        :return [(int, str)]: return a List of tuples. A tuple consist of
            publish sequence number and formatted article string.
        :raises FormatterError: if the formatter fails to format an article
        """
        try:
            pub_seq_num = superdesk.get_resource_service('subscribers').generate_sequence_number(subscriber)

            newsml = etree.Element("NewsML")
            SubElement(newsml, "Catalog", {'Href': 'http://www.iptc.org/std/catalog/catalog.IptcMasterCatalog.xml'})
            news_envelope = SubElement(newsml, "NewsEnvelope")
            news_item = SubElement(newsml, "NewsItem")

            self._format_news_envelope(article, news_envelope, pub_seq_num)
            self._format_identification(article, news_item)
            self._format_news_management(article, news_item)
            self._format_news_component(article, news_item)

            return [(pub_seq_num, self.XML_ROOT + etree.tostring(newsml).decode('utf-8'))]
        except Exception as ex:
            raise FormatterError.newml12FormatterError(ex, subscriber)
Esempio n. 4
0
    def format(self, article, subscriber, codes=None):
        """
        Create article in NewsML1.2 format

        :param dict article:
        :param dict subscriber:
        :param list codes:
        :return [(int, str)]: return a List of tuples. A tuple consist of
            publish sequence number and formatted article string.
        :raises FormatterError: if the formatter fails to format an article
        """
        try:
            pub_seq_num = superdesk.get_resource_service(
                "subscribers").generate_sequence_number(subscriber)
            self.now = utcnow()
            self.string_now = self.now.strftime("%Y%m%dT%H%M%S+0000")

            newsml = etree.Element("NewsML")
            SubElement(
                newsml, "Catalog", {
                    "Href":
                    "http://www.iptc.org/std/catalog/catalog.IptcMasterCatalog.xml"
                })
            news_envelope = SubElement(newsml, "NewsEnvelope")
            news_item = SubElement(newsml, "NewsItem")

            self._format_news_envelope(article, news_envelope, pub_seq_num)
            self._format_identification(article, news_item)
            self._format_news_management(article, news_item)
            self._format_news_component(article, news_item)

            return [(pub_seq_num, self.XML_ROOT + etree.tostring(
                newsml, encoding=self.ENCODING).decode(self.ENCODING))]
        except Exception as ex:
            raise FormatterError.newml12FormatterError(ex, subscriber)
    def format(self, article, subscriber, codes=None):
        """
        Create article in NewsML1.2 format

        :param dict article:
        :param dict subscriber:
        :param list codes:
        :return [(int, str)]: return a List of tuples. A tuple consist of
            publish sequence number and formatted article string.
        :raises FormatterError: if the formatter fails to format an article
        """
        try:
            formatted_article = deepcopy(article)
            pub_seq_num = superdesk.get_resource_service('subscribers').generate_sequence_number(subscriber)
            self.now = utcnow()
            self.string_now = self.now.strftime('%Y%m%dT%H%M%S+0000')

            newsml = etree.Element("NewsML", {'Version': '1.2'})
            SubElement(newsml, "Catalog", {
                'Href': 'http://about.reuters.com/newsml/vocabulary/catalog-reuters-3rdParty-master_catalog.xml'})
            news_envelope = SubElement(newsml, "NewsEnvelope")
            news_item = SubElement(newsml, "NewsItem")

            self._format_news_envelope(formatted_article, news_envelope, pub_seq_num)
            self._format_identification(formatted_article, news_item)
            self._format_news_management(formatted_article, news_item)
            self._format_news_component(formatted_article, news_item)

            return [(pub_seq_num, self.XML_ROOT + etree.tostring(newsml).decode('utf-8'))]
        except Exception as ex:
            raise FormatterError.newml12FormatterError(ex, subscriber)
Esempio n. 6
0
    def format(self, article, subscriber):
        try:
            pub_seq_num = superdesk.get_resource_service('subscribers').generate_sequence_number(subscriber)

            newsml = etree.Element("NewsML")
            SubElement(newsml, "Catalog", {'Href': 'http://www.aap.com.au/xml-res/aap-master-catalog.xml'})
            news_envelope = SubElement(newsml, "NewsEnvelope")
            news_item = SubElement(newsml, "NewsItem")

            self._format_news_envelope(article, news_envelope, pub_seq_num)
            self._format_identification(article, news_item)
            self._format_news_management(article, news_item)
            self._format_news_component(article, news_item)

            return [(pub_seq_num, self.XML_ROOT + etree.tostring(newsml).decode('utf-8'))]
        except Exception as ex:
            raise FormatterError.newml12FormatterError(ex, subscriber)
    def format(self, article, destination, selector_codes=None):
        try:

            pub_seq_num = superdesk.get_resource_service("output_channels").generate_sequence_number(destination)

            newsml = etree.Element("NewsML")
            SubElement(newsml, "Catalog", {"Href": "http://www.aap.com.au/xml-res/aap-master-catalog.xml"})
            news_envelope = SubElement(newsml, "NewsEnvelope")
            news_item = SubElement(newsml, "NewsItem")

            self._format_news_envelope(article, news_envelope, pub_seq_num)
            self._format_identification(article, news_item)
            self._format_news_management(article, news_item)
            self._format_news_component(article, news_item)

            return pub_seq_num, self.XML_ROOT + etree.tostring(newsml).decode("utf-8")
        except Exception as ex:
            raise FormatterError.newml12FormatterError(ex, destination)