예제 #1
0
    def output_feed(self, results, feed_title, feed_description,
                    feed_link, feed_url, navigation_urls, feed_guid):

        author_name = config.get('ckan.feeds.author_name', '').strip() or \
            config.get('ckan.site_id', '').strip()
        author_link = config.get('ckan.feeds.author_link', '').strip() or \
            config.get('ckan.site_url', '').strip()

        feed = _FixedAtom1Feed(
            title=feed_title,
            link=feed_link,
            description=feed_description,
            language=u'en',
            author_name=author_name,
            author_link=author_link,
            feed_guid=feed_guid,
            feed_url=feed_url,
            previous_page=navigation_urls['previous'],
            next_page=navigation_urls['next'],
            first_page=navigation_urls['first'],
            last_page=navigation_urls['last'],
        )

        if c.language == 'fr':
            def lx(x):
                return x + '_fra'
        else:
            def lx(x):
                return x

        for pkg in results:
            feed.add_item(
                title=pkg.get(lx('title'), ''),
                link=self.base_url + url(str(
                    '/api/action/package_show?id=%s' % pkg['name'])
                ),
                description=pkg.get(lx('notes'), ''),
                updated=date_str_to_datetime(pkg.get('metadata_modified')),
                published=date_str_to_datetime(pkg.get('metadata_created')),
                unique_id=_create_atom_id(u'/dataset/%s' % pkg['id']),
                author_name=pkg.get('author', ''),
                author_email=pkg.get('author_email', ''),
                categories=''.join(e['value']
                                   for e in pkg.get('extras', [])
                                   if e['key'] == lx('keywords')).split(','),
                enclosure=webhelpers.feedgenerator.Enclosure(
                    self.base_url + url(str(
                        '/api/action/package_show?id=%s' % pkg['name'])),
                    unicode(len(json.dumps(pkg))),   # TODO fix this
                    u'application/json')
            )
        response.content_type = feed.mime_type
        return feed.writeString('utf-8')
예제 #2
0
    def output_feed(self, results, feed_title, feed_description, feed_link,
                    feed_url, navigation_urls, feed_guid):

        author_name = config.get('ckan.feeds.author_name', '').strip() or \
            config.get('ckan.site_id', '').strip()
        author_link = config.get('ckan.feeds.author_link', '').strip() or \
            config.get('ckan.site_url', '').strip()

        feed = _FixedAtom1Feed(
            title=feed_title,
            link=feed_link,
            description=feed_description,
            language=u'en',
            author_name=author_name,
            author_link=author_link,
            feed_guid=feed_guid,
            feed_url=feed_url,
            previous_page=navigation_urls['previous'],
            next_page=navigation_urls['next'],
            first_page=navigation_urls['first'],
            last_page=navigation_urls['last'],
        )

        if c.language == 'fr':

            def lx(x):
                return x + '_fra'
        else:

            def lx(x):
                return x

        for pkg in results:
            feed.add_item(
                title=pkg.get(lx('title'), ''),
                link=self.base_url +
                url(str('/api/action/package_show?id=%s' % pkg['name'])),
                description=pkg.get(lx('notes'), ''),
                updated=date_str_to_datetime(pkg.get('metadata_modified')),
                published=date_str_to_datetime(pkg.get('metadata_created')),
                unique_id=_create_atom_id(u'/dataset/%s' % pkg['id']),
                author_name=pkg.get('author', ''),
                author_email=pkg.get('author_email', ''),
                categories=''.join(e['value'] for e in pkg.get('extras', [])
                                   if e['key'] == lx('keywords')).split(','),
                enclosure=webhelpers.feedgenerator.Enclosure(
                    self.base_url +
                    url(str('/api/action/package_show?id=%s' % pkg['name'])),
                    unicode(len(json.dumps(pkg))),  # TODO fix this
                    u'application/json'))
        response.content_type = feed.mime_type
        return feed.writeString('utf-8')
예제 #3
0
    def output_feed(self, results, feed_title, feed_description, feed_link, feed_url, navigation_urls, feed_guid):

        author_name = config.get("ckan.feeds.author_name", "").strip() or config.get("ckan.site_id", "").strip()
        author_link = config.get("ckan.feeds.author_link", "").strip() or config.get("ckan.site_url", "").strip()

        feed = _FixedAtom1Feed(
            title=feed_title,
            link=feed_link,
            description=feed_description,
            language=u"en",
            author_name=author_name,
            author_link=author_link,
            feed_guid=feed_guid,
            feed_url=feed_url,
            previous_page=navigation_urls["previous"],
            next_page=navigation_urls["next"],
            first_page=navigation_urls["first"],
            last_page=navigation_urls["last"],
        )

        if c.language == "fr":

            def lx(x):
                return x + "_fra"

        else:

            def lx(x):
                return x

        for pkg in results:
            feed.add_item(
                title=pkg.get(lx("title"), ""),
                link=self.base_url + url(str("/api/action/package_show?id=%s" % pkg["name"])),
                description=pkg.get(lx("notes"), ""),
                updated=date_str_to_datetime(pkg.get("metadata_modified")),
                published=date_str_to_datetime(pkg.get("metadata_created")),
                unique_id=_create_atom_id(u"/dataset/%s" % pkg["id"]),
                author_name=pkg.get("author", ""),
                author_email=pkg.get("author_email", ""),
                categories="".join(e["value"] for e in pkg.get("extras", []) if e["key"] == lx("keywords")).split(","),
                enclosure=webhelpers.feedgenerator.Enclosure(
                    self.base_url + url(str("/api/action/package_show?id=%s" % pkg["name"])),
                    unicode(len(json.dumps(pkg))),  # TODO fix this
                    u"application/json",
                ),
            )
        response.content_type = feed.mime_type
        return feed.writeString("utf-8")
예제 #4
0
파일: feed.py 프로젝트: okfn/ckanext-lcrnz
    def output_feed(self, results, feed_title, feed_description,
                    feed_link, feed_url, navigation_urls, feed_guid):
        author_name = config.get('ckan.feeds.author_name', '').strip() or \
            config.get('ckan.site_id', '').strip()
        author_link = config.get('ckan.feeds.author_link', '').strip() or \
            config.get('ckan.site_url', '').strip()

        # TODO language
        feed = _FixedAtom1Feed(
            title=feed_title,
            link=feed_link,
            description=feed_description,
            language=u'en',
            author_name=author_name,
            author_link=author_link,
            feed_guid=feed_guid,
            feed_url=feed_url,
            previous_page=navigation_urls['previous'],
            next_page=navigation_urls['next'],
            first_page=navigation_urls['first'],
            last_page=navigation_urls['last'],
        )

        for pkg in results:
            feed.add_item(
                title=pkg.get('title', ''),
                link=self.base_url + h.url_for(controller='package',
                                               action='read',
                                               id=pkg['id']),
                description=pkg.get('notes', ''),
                updated=h.date_str_to_datetime(pkg.get('metadata_modified')),
                published=h.date_str_to_datetime(pkg.get('metadata_created')),
                unique_id=_create_atom_id(u'dataset/%s' % pkg['id']),
                author_name=';'.join(str(x) for x in pkg.get('author','')),
                author_email=pkg.get('author_email', ''),
                categories=[t['name'] for t in pkg.get('tags', [])],
                enclosure=webhelpers.feedgenerator.Enclosure(
                    self.base_url + h.url_for(controller='api',
                                              register='package',
                                              action='show',
                                              id=pkg['name'],
                                              ver='2'),
                    unicode(len(json.dumps(pkg))),   # TODO fix this
                    u'application/json')
            )
        response.content_type = feed.mime_type
        return feed.writeString('utf-8')
예제 #5
0
    def output_feed(self, results, feed_title, feed_description, feed_link,
                    feed_url, navigation_urls, feed_guid):
        author_name = config.get('ckan.feeds.author_name', '').strip() or \
            config.get('ckan.site_id', '').strip()
        author_link = config.get('ckan.feeds.author_link', '').strip() or \
            config.get('ckan.site_url', '').strip()

        feed = _FixedAtom1Feed(
            title=feed_title,
            link=feed_link,
            description=feed_description,
            language='es',
            author_name=author_name,
            author_link=author_link,
            feed_guid=feed_guid,
            feed_url=feed_url,
            previous_page=navigation_urls['previous'],
            next_page=navigation_urls['next'],
            first_page=navigation_urls['first'],
            last_page=navigation_urls['last'],
        )

        for pkg in results:
            description = pkg.get('description', '').get('es', '')
            feed.add_item(
                title=pkg.get('title', ''),
                link=self.base_url +
                h.url_for(controller='package', action='read', id=pkg['name']),
                description=description,
                updated=self._dge_date_str_to_datetime(
                    pkg.get('metadata_modified')),
                published=self._dge_date_str_to_datetime(
                    pkg.get('metadata_created')),
                unique_id=_create_atom_id(u'/catalogo/%s' % pkg['name']),
                author_name=pkg.get('author_name', ''),
                author_email=pkg.get('author_email', ''),
                categories=[t['name'] for t in pkg.get('tags', [])],
                enclosure=None,
            )
        response.content_type = feed.mime_type
        return feed.writeString('utf-8')