コード例 #1
0
    def get_feed_parser(self, provider, article=None):
        """
        Returns instance of configured feed parser for the given provider.

        :param provider: Ingest Provider Details.
        :type provider: dict :py:class: `superdesk.io.ingest_provider_model.IngestProviderResource`
        :param article: article which needs to parsed by the parser, defaults to None. When None, the registered parser
                        will be returned without checking if the parser can parse the article.
        :return: Feed Parser instance.
        :rtype: :py:class:`superdesk.io.feed_parsers.FeedParser`
        :raises: SuperdeskIngestError.parserNotFoundError()
                    if either feed_parser value is empty or Feed Parser not found.
        """

        parser = registered_feed_parsers.get(provider.get('feed_parser', ''))
        if not parser:
            raise SuperdeskIngestError.parserNotFoundError(provider=provider)

        if article is not None and not parser.can_parse(article):
            raise SuperdeskIngestError.parserNotFoundError(provider=provider)

        if article is not None:
            parser = parser.__class__()

        return parser
コード例 #2
0
    def get_feed_parser(self, provider, article=None):
        """
        Returns instance of configured feed parser for the given provider.

        :param provider: Ingest Provider Details.
        :type provider: dict :py:class: `superdesk.io.ingest_provider_model.IngestProviderResource`
        :param article: article which needs to parsed by the parser, defaults to None. When None, the registered parser
                        will be returned without checking if the parser can parse the article.
        :return: Feed Parser instance.
        :rtype: :py:class:`superdesk.io.feed_parsers.FeedParser`
        :raises: SuperdeskIngestError.parserNotFoundError()
                    if either feed_parser value is empty or Feed Parser not found.
        """

        parser = registered_feed_parsers.get(provider.get('feed_parser', ''))
        if not parser:
            raise SuperdeskIngestError.parserNotFoundError(provider=provider)

        if article is not None and not parser.can_parse(article):
            raise SuperdeskIngestError.parserNotFoundError(provider=provider)

        if article is not None:
            parser = parser.__class__()

        return parser
コード例 #3
0
    def test_ingest_update_same_event(self):
        xml = ET.fromstring("""<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
            <document>
            <guid>NTB-123456</guid>
            <time>2016-08-10T15:02:02</time>
            <publiseres>True</publiseres>
            <ntbId>NBRP160810_144545_ja_00</ntbId>
            <service>newscalendar</service>
            <title>Original Content</title>
            <location>Fr. Nansens plass 17, Tromsø, Troms</location>
            <timeStart>2016-09-05T09:00:00</timeStart>
            <timeEnd>2016-09-05T16:00:00</timeEnd>
            <alldayevent>False</alldayevent>
            <priority>5</priority>
            <regions>
            <region>Norge</region>
            </regions>
            <districts>
            <district parent="Norge">Troms</district>
            </districts>
            <category>Innenriks</category>
            <subcategory>Redplan element</subcategory>
            <subjects>
            <subject>Kriminalitet og rettsvesen</subject>
            <subject parent="Kriminalitet">Drap;Rettssaker</subject>
            </subjects>
            <emailwriter>[email protected]</emailwriter>
            <messagetype>Redplan redaksjon</messagetype>
            <geo>
            <latitude>69.65482639999999</latitude>
            <longitude>18.96509590000005</longitude>
            </geo>
            <content>Original Content</content>
            <mediaList>
            <media id="" mediaType="" mimeType="ukjent">
            <caption></caption>
            </media>
            </mediaList>
            </document>""")

        with self.app.test_request_context(self.app.config['URL_PREFIX']):
            # ingest event
            events = self.get_parsed_documents(registered_feed_parsers.get('ntb_event_xml'), xml)
            provider = get_resource_service('ingest_providers').find_one(req=None, _id=self.providers.get('ntbevent'))
            self.ingest_items(events, provider, registered_feeding_services.get('event_file'))
            ingested_event = get_resource_service('events').find_one(req=None, _id='NTB-123456')
            self.assertTrue(ingested_event['_id'], 'NTB-123456')
            self.assertTrue(ingested_event['name'], 'Original Content')
            self.assertTrue(ingested_event['dates']['start'], '2016-09-05T09:00:00')
            self.assertTrue(ingested_event['dates']['end'], '2016-09-05T16:00:00')
            self.assertTrue(ingested_event['_planning_schedule'][0]['scheduled'], '2016-09-05T09:00:00')

            # ingest updated event
            events = self.get_parsed_documents(registered_feed_parsers.get('ntb_event_xml'), xml)
            events[0]['dates']['start'] = '2016-09-06T10:00:00'
            events[0]['dates']['end'] = '2016-09-06T14:00:00'
            events[0]['name'] = 'Updated Content'
            self.ingest_items(events, provider, registered_feeding_services.get('event_file'))
            ingested_event = get_resource_service('events').find_one(req=None, _id='NTB-123456')
            self.assertTrue(ingested_event['_id'], 'NTB-123456')
            self.assertTrue(ingested_event['name'], 'Updated Content')
            self.assertTrue(ingested_event['dates']['start'], '2016-09-05T09:00:00')
            self.assertTrue(ingested_event['dates']['end'], '2016-09-05T16:00:00')
            self.assertTrue(ingested_event['_planning_schedule'][0]['scheduled'], '2016-09-16T16:00:00')