本文整理汇总了Python中superdesk.errors.FormatterError.newml12FormatterError方法的典型用法代码示例。如果您正苦于以下问题:Python FormatterError.newml12FormatterError方法的具体用法?Python FormatterError.newml12FormatterError怎么用?Python FormatterError.newml12FormatterError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类superdesk.errors.FormatterError
的用法示例。
在下文中一共展示了FormatterError.newml12FormatterError方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: format
# 需要导入模块: from superdesk.errors import FormatterError [as 别名]
# 或者: from superdesk.errors.FormatterError import newml12FormatterError [as 别名]
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)
示例2: format
# 需要导入模块: from superdesk.errors import FormatterError [as 别名]
# 或者: from superdesk.errors.FormatterError import newml12FormatterError [as 别名]
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)
示例3: format
# 需要导入模块: from superdesk.errors import FormatterError [as 别名]
# 或者: from superdesk.errors.FormatterError import newml12FormatterError [as 别名]
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)
示例4: format
# 需要导入模块: from superdesk.errors import FormatterError [as 别名]
# 或者: from superdesk.errors.FormatterError import newml12FormatterError [as 别名]
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)