def format(self, article, subscriber): try: pub_seq_num = superdesk.get_resource_service('subscribers').generate_sequence_number(subscriber) ninjs = { '_id': article['_id'], 'version': str(article['_current_version']), 'type': self._get_type(article) } try: ninjs['byline'] = self._get_byline(article) except: pass for copy_property in self.direct_copy_properties: if copy_property in article: ninjs[copy_property] = article[copy_property] if 'description' in article: ninjs['description_text'] = article['description'] if article['type'] == 'composite': ninjs['associations'] = self._get_associations(article) return [(pub_seq_num, json.dumps(ninjs, default=json_serialize_datetime_objectId))] except Exception as ex: raise FormatterError.ninjsFormatterError(ex, subscriber)
def format(self, article, subscriber): try: pub_seq_num = superdesk.get_resource_service('subscribers').generate_sequence_number(subscriber) ninjs = { '_id': article['_id'], 'version': str(article['_current_version']), 'type': self._get_type(article) } try: ninjs['byline'] = self._get_byline(article) except: pass located = article.get('dateline', {}).get('located', {}).get('city') if located: ninjs['located'] = article.get('dateline', {}).get('located', {}).get('city', '') for copy_property in self.direct_copy_properties: if copy_property in article: ninjs[copy_property] = article[copy_property] if 'description' in article: ninjs['description_text'] = article['description'] if article[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE: ninjs['associations'] = self._get_associations(article) if article.get(EMBARGO): ninjs['embargoed'] = article.get(EMBARGO).isoformat() return [(pub_seq_num, json.dumps(ninjs, default=json_serialize_datetime_objectId))] except Exception as ex: raise FormatterError.ninjsFormatterError(ex, subscriber)
def format(self, article, subscriber): try: pub_seq_num = superdesk.get_resource_service('subscribers').generate_sequence_number(subscriber) ninjs = { '_id': article['_id'], 'version': str(article.get(config.VERSION, 1)), 'type': self._get_type(article) } try: ninjs['byline'] = self._get_byline(article) except: pass located = article.get('dateline', {}).get('located', {}) if located: ninjs['located'] = located.get('city', '') for copy_property in self.direct_copy_properties: if article.get(copy_property) is not None: ninjs[copy_property] = article[copy_property] if article.get('body_html'): ninjs['body_html'] = self.append_body_footer(article) if article.get('description'): ninjs['description_html'] = self.append_body_footer(article) if article[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE: ninjs['associations'] = self._get_associations(article) elif article.get('associations', {}): ninjs['associations'] = self._format_related(article, subscriber) if article.get(EMBARGO): ninjs['embargoed'] = article.get(EMBARGO).isoformat() if article.get('priority'): ninjs['priority'] = article['priority'] else: ninjs['priority'] = 5 if article.get('subject'): ninjs['subject'] = self._get_subject(article) if article.get('anpa_category'): ninjs['service'] = self._get_service(article) if article.get('renditions'): ninjs['renditions'] = self._get_renditions(article) if article.get('abstract'): ninjs['description_text'] = article.get('abstract') elif article.get('description_text'): ninjs['description_text'] = article.get('description_text') return [(pub_seq_num, json.dumps(ninjs, default=json_serialize_datetime_objectId))] except Exception as ex: raise FormatterError.ninjsFormatterError(ex, subscriber)
def format(self, article, subscriber, codes=None): try: pub_seq_num = superdesk.get_resource_service('subscribers').generate_sequence_number(subscriber) ninjs = self._transform_to_ninjs(article, subscriber) return [(pub_seq_num, json.dumps(ninjs, default=json_serialize_datetime_objectId))] except Exception as ex: raise FormatterError.ninjsFormatterError(ex, subscriber)
def format(self, article, subscriber): try: pub_seq_num = superdesk.get_resource_service( 'subscribers').generate_sequence_number(subscriber) ninjs = { '_id': article['_id'], 'version': str(article.get(config.VERSION, 1)), 'type': self._get_type(article) } try: ninjs['byline'] = self._get_byline(article) except: pass located = article.get('dateline', {}).get('located', {}) if located: ninjs['located'] = located.get('city', '') for copy_property in self.direct_copy_properties: if article.get(copy_property) is not None: ninjs[copy_property] = article[copy_property] if article.get('body_html'): ninjs['body_html'] = self.append_body_footer(article) if article.get('description'): ninjs['description_html'] = self.append_body_footer(article) if article[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE: ninjs['associations'] = self._get_associations(article) elif article.get('associations', {}): ninjs['associations'] = self._format_related( article, subscriber) if article.get(EMBARGO): ninjs['embargoed'] = article.get(EMBARGO).isoformat() if article.get('priority'): ninjs['priority'] = article['priority'] else: ninjs['priority'] = 5 if article.get('subject'): ninjs['subject'] = self._get_subject(article) if article.get('anpa_category'): ninjs['service'] = self._get_service(article) if article.get('renditions'): ninjs['renditions'] = self._get_renditions(article) return [(pub_seq_num, json.dumps(ninjs, default=json_serialize_datetime_objectId))] except Exception as ex: raise FormatterError.ninjsFormatterError(ex, subscriber)
def format(self, article, subscriber, codes=None): try: pub_seq_num = superdesk.get_resource_service('subscribers').generate_sequence_number(subscriber) ninjs = self._transform_to_ninjs(self._merge_versions(article), subscriber) ninjs['extra'] = {'published_id': article.get('_id')} # If the item was ingested and auto-published, the guid is set to the ingest_id # which in FileFeeds will be the path to the file that was ingested # [STTNHUB-58] - Auto published ingested items should preserve id # (https://github.com/superdesk/superdesk-core/pull/1579) # Change the guid back to using the family_id of the item if (ninjs.get(GUID_FIELD) or '').startswith('/mnt/'): ninjs[GUID_FIELD] = article.get(FAMILY_ID) return [(pub_seq_num, json.dumps(ninjs, default=json_serialize_datetime_objectId))] except Exception as ex: raise FormatterError.ninjsFormatterError(ex, subscriber)
def format(self, article, subscriber, codes=None): try: pub_seq_num = superdesk.get_resource_service('subscribers').generate_sequence_number(subscriber) ninjs = self._transform_to_ninjs(article, subscriber) # if the article has an abstract then the description text has been over written by the abstract if article.get('abstract'): # if it is a picture then put it back if article.get('type') == 'picture': ninjs['description_text'] = article.get('description_text', '') media = article.get('associations', {}).get('featuremedia') ninjs_media = article.get('associations', {}).get('featuremedia') if media and media.get('type') == 'picture': ninjs_media['description_text'] = media.get('description_text') return [(pub_seq_num, json.dumps(ninjs, default=json_serialize_datetime_objectId))] except Exception as ex: raise FormatterError.ninjsFormatterError(ex, subscriber)
def format(self, article, destination, selector_codes=None): try: pub_seq_num = superdesk.get_resource_service('output_channels').generate_sequence_number(destination) ninjs = {} ninjs['_id'] = article['_id'] ninjs['version'] = str(article['version']) ninjs['type'] = self._get_type(article) try: ninjs['byline'] = self._get_byline(article) except: pass for copy_property in self.direct_copy_properties: if copy_property in article: ninjs[copy_property] = article[copy_property] if article['type'] == 'composite': article['associations'] = self._get_associations(article) return pub_seq_num, json.dumps(ninjs, default=json_util.default) except Exception as ex: raise FormatterError.ninjsFormatterError(ex, destination)
def format(self, article, subscriber, codes=None): try: pub_seq_num = superdesk.get_resource_service( 'subscribers').generate_sequence_number(subscriber) ninjs = self._transform_to_ninjs(article, subscriber) # if the article has an abstract then the description text has been over written by the abstract if article.get('abstract'): # if it is a picture then put it back if article.get('type') == 'picture': ninjs['description_text'] = article.get( 'description_text', '') media = article.get('associations', {}).get('featuremedia') ninjs_media = article.get('associations', {}).get('featuremedia') if media and media.get('type') == 'picture': ninjs_media['description_text'] = media.get('description_text') return [(pub_seq_num, json.dumps(ninjs, default=json_serialize_datetime_objectId))] except Exception as ex: raise FormatterError.ninjsFormatterError(ex, subscriber)