コード例 #1
0
ファイル: entry.py プロジェクト: newscred/python-feedgen
	def contributor(self, contributor=None, replace=False, **kwargs):
		'''Get or set the contributor data of the feed. This is an ATOM only
		value.

		This method can be called with:
		- the fields of an contributor as keyword arguments
		- the fields of an contributor as a dictionary
		- a list of dictionaries containing the contributor fields

		An contributor has the following fields:
		- *name* conveys a human-readable name for the person.
		- *uri* contains a home page for the person.
		- *email* contains an email address for the person.

		:param contributor: Dictionary or list of dictionaries with contributor data.
		:param replace: Add or replace old data.
		:returns: List of contributors as dictionaries.
		'''
		if contributor is None and kwargs:
			contributor = kwargs
		if not contributor is None:
			if replace or self.__atom_contributor is None:
				self.__atom_contributor = []
			self.__atom_contributor += ensure_format( contributor,
					set(['name', 'email', 'uri']), set(['name']))
		return self.__atom_contributor
コード例 #2
0
    def category(self, category=None, replace=False, **kwargs):
        """Get or set categories that the entry belongs to.

        This method can be called with:
        - the fields of a category as keyword arguments
        - the fields of a category as a dictionary
        - a list of dictionaries containing the category fields
        A categories has the following fields:
        - *term* identifies the category
        - *scheme* identifies the categorization scheme via a URI.
        - *label* provides a human-readable label for display
        If a label is present it is used for the RSS feeds. Otherwise the term
        is used. The scheme is used for the domain attribute in RSS.
        :param category:    Dict or list of dicts with data.
        :param replace: Add or replace old data.
        :returns: List of category data.
        """
        if category is None and kwargs:
            category = kwargs
        if category is not None:
            if replace or self.__atom_category is None:
                self.__atom_category = []
            self.__atom_category += ensure_format(
                category, set(['term', 'scheme', 'label']), set(['term']))
            # Map the ATOM categories to RSS categories. Use the atom:label as
            # name or if not present the atom:term. The atom:scheme is the
            # rss:domain.
            self.__rss_category = []
            for cat in self.__atom_category:
                rss_cat = {}
                rss_cat['value'] = cat.get('label', cat['term'])
                if cat.get('scheme'):
                    rss_cat['domain'] = cat['scheme']
                self.__rss_category.append(rss_cat)
        return self.__atom_category
コード例 #3
0
ファイル: entry.py プロジェクト: woshishipeiyu/python-feedgen
    def contributor(self, contributor=None, replace=False, **kwargs):
        '''Get or set the contributor data of the feed. This is an ATOM only
        value.

        This method can be called with:
        - the fields of an contributor as keyword arguments
        - the fields of an contributor as a dictionary
        - a list of dictionaries containing the contributor fields

        An contributor has the following fields:
        - *name* conveys a human-readable name for the person.
        - *uri* contains a home page for the person.
        - *email* contains an email address for the person.

        :param contributor: Dictionary or list of dictionaries with contributor
                            data.
        :param replace: Add or replace old data.
        :returns: List of contributors as dictionaries.
        '''
        if contributor is None and kwargs:
            contributor = kwargs
        if contributor is not None:
            if replace or self.__atom_contributor is None:
                self.__atom_contributor = []
            self.__atom_contributor += ensure_format(
                contributor, set(['name', 'email', 'uri']), set(['name']))
        return self.__atom_contributor
コード例 #4
0
    def link(self, link=None, replace=False, **kwargs):
        """Get or set link data. An link element is a dict with the fields.

        href, rel, type, hreflang, title, and length. Href is mandatory for
        ATOM.
        This method can be called with:
        - the fields of a link as keyword arguments
        - the fields of a link as a dictionary
        - a list of dictionaries containing the link fields
        A link has the following fields:
        - *href* is the URI of the referenced resource (typically a Web page)
        - *rel* contains a single link relationship type. It can be a full URI,
          or one of the following predefined values (default=alternate):
            - *alternate* an alternate representation of the entry or feed, for
              example a permalink to the html version of the entry, or the
              front page of the weblog.
            - *enclosure* a related resource which is potentially large in size
              and might require special handling, for example an audio or video
              recording.
            - *related* an document related to the entry or feed.
            - *self* the feed itself.
            - *via* the source of the information provided in the entry.
        - *type* indicates the media type of the resource.
        - *hreflang* indicates the language of the referenced resource.
        - *title* human readable information about the link, typically for
          display purposes.
        - *length* the length of the resource, in bytes.
        RSS only supports one link with nothing but a URL. So for the RSS link
        element the last link with rel=alternate is used.
        RSS also supports one enclusure element per entry which is covered by
        the link element in ATOM feed entries. So for the RSS enclusure element
        the last link with rel=enclosure is used.
        :param link:    Dict or list of dicts with data.
        :param replace: Add or replace old data.
        :returns: List of link data.
        """
        if link is None and kwargs:
            link = kwargs
        if link is not None:
            if replace or self.__atom_link is None:
                self.__atom_link = []
            self.__atom_link += ensure_format(
                link,
                set(['href', 'rel', 'type', 'hreflang', 'title', 'length']),
                set(['href']),
                {'rel': ['alternate', 'enclosure', 'related', 'self', 'via']},
                {'rel': 'alternate'})
            # RSS only needs one URL. We use the first link for RSS:
            for l in self.__atom_link:
                if l.get('rel') == 'alternate':
                    self.__rss_link = l['href']
                elif l.get('rel') == 'enclosure':
                    self.__rss_enclosure = {'url': l['href']}
                    self.__rss_enclosure['type'] = l.get('type')
                    self.__rss_enclosure['length'] = l.get('length') or '0'
        # return the set with more information (atom)
        return self.__atom_link
コード例 #5
0
ファイル: feed.py プロジェクト: meteozond/python-feedgen
    def link(self, link=None, replace=False, **kwargs):
        '''Get or set link data. An link element is a dict with the fields href,
		rel, type, hreflang, title, and length. Href is mandatory for ATOM.

		This method can be called with:
		- the fields of a link as keyword arguments
		- the fields of a link as a dictionary
		- a list of dictionaries containing the link fields

		A link has the following fields:

		- *href* is the URI of the referenced resource (typically a Web page)
		- *rel* contains a single link relationship type. It can be a full URI,
		  or one of the following predefined values (default=alternate):

			- *alternate* an alternate representation of the entry or feed, for
			  example a permalink to the html version of the entry, or the front
			  page of the weblog.
			- *enclosure* a related resource which is potentially large in size
			  and might require special handling, for example an audio or video
			  recording.
			- *related* an document related to the entry or feed.
			- *self* the feed itself.
			- *via* the source of the information provided in the entry.

		- *type* indicates the media type of the resource.
		- *hreflang* indicates the language of the referenced resource.
		- *title* human readable information about the link, typically for
		  display purposes.
		- *length* the length of the resource, in bytes.

		RSS only supports one link with URL only.
		
		:param link:    Dict or list of dicts with data.
		:param replace: Add or replace old data.

		Example::

			>>> feedgen.link( href='http://example.com/', rel='self')
			[{'href':'http://example.com/', 'rel':'self'}]

		'''
        if link is None and kwargs:
            link = kwargs
        if not link is None:
            if replace or self.__atom_link is None:
                self.__atom_link = []
            self.__atom_link += ensure_format(
                link,
                set(['href', 'rel', 'type', 'hreflang', 'title', 'length']),
                set(['href']),
                {'rel': ['alternate', 'enclosure', 'related', 'self', 'via']})
            # RSS only needs one URL. We use the first link for RSS:
            if len(self.__atom_link) > 0:
                self.__rss_link = self.__atom_link[-1]['href']
        # return the set with more information (atom)
        return self.__atom_link
コード例 #6
0
ファイル: feed.py プロジェクト: ngulden/python-feedgen
	def link(self, link=None, replace=False, **kwargs):
		'''Get or set link data. An link element is a dict with the fields href,
		rel, type, hreflang, title, and length. Href is mandatory for ATOM.

		This method can be called with:
		- the fields of a link as keyword arguments
		- the fields of a link as a dictionary
		- a list of dictionaries containing the link fields

		A link has the following fields:

		- *href* is the URI of the referenced resource (typically a Web page)
		- *rel* contains a single link relationship type. It can be a full URI,
		  or one of the following predefined values (default=alternate):

			- *alternate* an alternate representation of the entry or feed, for
			  example a permalink to the html version of the entry, or the front
			  page of the weblog.
			- *enclosure* a related resource which is potentially large in size
			  and might require special handling, for example an audio or video
			  recording.
			- *related* an document related to the entry or feed.
			- *self* the feed itself.
			- *via* the source of the information provided in the entry.

		- *type* indicates the media type of the resource.
		- *hreflang* indicates the language of the referenced resource.
		- *title* human readable information about the link, typically for
		  display purposes.
		- *length* the length of the resource, in bytes.

		RSS only supports one link with URL only.
		
		:param link:    Dict or list of dicts with data.
		:param replace: Add or replace old data.

		Example::

			>>> feedgen.link( href='http://example.com/', rel='self')
			[{'href':'http://example.com/', 'rel':'self'}]

		'''
		if link is None and kwargs:
			link = kwargs
		if not link is None:
			if replace or self.__atom_link is None:
				self.__atom_link = []
			self.__atom_link += ensure_format( link, 
					set(['href', 'rel', 'type', 'hreflang', 'title', 'length']),
					set(['href']), 
					{'rel':['alternate', 'enclosure', 'related', 'self', 'via']} )
			# RSS only needs one URL. We use the first link for RSS:
			if len(self.__atom_link) > 0:
				self.__rss_link = self.__atom_link[-1]['href']
		# return the set with more information (atom)
		return self.__atom_link
コード例 #7
0
    def thumbnail(self,
                  thumbnail=None,
                  replace=False,
                  group='default',
                  **kwargs):
        '''Get or set media:thumbnail data.

        This method can be called with:
        - the fields of a media:content as keyword arguments
        - the fields of a media:content as a dictionary
        - a list of dictionaries containing the media:content fields

        Allows particular images to be used as representative images for
        the media object. If multiple thumbnails are included, and time
        coding is not at play, it is assumed that the images are in order
        of importance. It has one required attribute and three optional
        attributes.

        media:thumbnail has the following fields:
        - *url* should specify the direct URL to the media object.
        - *height* height of the media object.
        - *width* width of the media object.
        - *time* specifies the time offset in relation to the media object.

        :param thumbnail: Dictionary or list of dictionaries with thumbnail
                          data.
        :param replace: Add or replace old data.
        :param group: Media group to put this content in.

        :returns: The media thumbnail tag.
        '''
        # Handle kwargs
        if thumbnail is None and kwargs:
            thumbnail = kwargs
        # Handle new data
        if thumbnail is not None:
            # Reset data if we want to replace them
            if replace or self.__media_thumbnail is None:
                self.__media_thumbnail = []
            # Ensure list
            if not isinstance(thumbnail, list):
                thumbnail = [thumbnail]
            # Define media group
            for t in thumbnail:
                t['group'] = t.get('group', group)
            self.__media_thumbnail += ensure_format(
                thumbnail, set(['url', 'height', 'width', 'time', 'group']),
                set(['url', 'group']))
        return self.__media_thumbnail
コード例 #8
0
ファイル: feed.py プロジェクト: lkiesow/python-feedgen
    def author(self, author=None, replace=False, **kwargs):
        '''Get or set author data. An author element is a dictionary containing
        a name, an email address and a URI. Name is mandatory for ATOM, email
        is mandatory for RSS.

        This method can be called with:

        - the fields of an author as keyword arguments
        - the fields of an author as a dictionary
        - a list of dictionaries containing the author fields

        An author has the following fields:

        - *name* conveys a human-readable name for the person.
        - *uri* contains a home page for the person.
        - *email* contains an email address for the person.

        :param author:  Dictionary or list of dictionaries with author data.
        :param replace: Add or replace old data.
        :returns: List of authors as dictionaries.

        Example::

            >>> feedgen.author({'name':'John Doe', 'email':'*****@*****.**'})
            [{'name':'John Doe','email':'*****@*****.**'}]

            >>> feedgen.author([{'name':'Mr. X'},{'name':'Max'}])
            [{'name':'John Doe','email':'*****@*****.**'},
                    {'name':'John Doe'}, {'name':'Max'}]

            >>> feedgen.author(name='John Doe', email='*****@*****.**',
                               replace=True)
            [{'name':'John Doe','email':'*****@*****.**'}]

        '''
        if author is None and kwargs:
            author = kwargs
        if author is not None:
            if replace or self.__atom_author is None:
                self.__atom_author = []
            self.__atom_author += ensure_format(author,
                                                set(['name', 'email', 'uri']),
                                                set(['name']))
            self.__rss_author = []
            for a in self.__atom_author:
                if a.get('email'):
                    self.__rss_author.append(a['email'])
        return self.__atom_author
コード例 #9
0
    def author(self, author=None, replace=False, **kwargs):
        '''Get or set author data. An author element is a dictionary containing
        a name, an email address and a URI. Name is mandatory for ATOM, email
        is mandatory for RSS.

        This method can be called with:

        - the fields of an author as keyword arguments
        - the fields of an author as a dictionary
        - a list of dictionaries containing the author fields

        An author has the following fields:

        - *name* conveys a human-readable name for the person.
        - *uri* contains a home page for the person.
        - *email* contains an email address for the person.

        :param author:  Dictionary or list of dictionaries with author data.
        :param replace: Add or replace old data.
        :returns: List of authors as dictionaries.

        Example::

            >>> feedgen.author({'name':'John Doe', 'email':'*****@*****.**'})
            [{'name':'John Doe','email':'*****@*****.**'}]

            >>> feedgen.author([{'name':'Mr. X'},{'name':'Max'}])
            [{'name':'John Doe','email':'*****@*****.**'},
                    {'name':'John Doe'}, {'name':'Max'}]

            >>> feedgen.author(name='John Doe', email='*****@*****.**',
                               replace=True)
            [{'name':'John Doe','email':'*****@*****.**'}]

        '''
        if author is None and kwargs:
            author = kwargs
        if author is not None:
            if replace or self.__atom_author is None:
                self.__atom_author = []
            self.__atom_author += ensure_format(author,
                                                set(['name', 'email', 'uri']),
                                                set(['name']))
            self.__rss_author = []
            for a in self.__atom_author:
                if a.get('email'):
                    self.__rss_author.append(a['email'])
        return self.__atom_author
コード例 #10
0
ファイル: media.py プロジェクト: lkiesow/python-feedgen
    def thumbnail(self, thumbnail=None, replace=False, group='default',
                  **kwargs):
        '''Get or set media:thumbnail data.

        This method can be called with:
        - the fields of a media:content as keyword arguments
        - the fields of a media:content as a dictionary
        - a list of dictionaries containing the media:content fields

        Allows particular images to be used as representative images for
        the media object. If multiple thumbnails are included, and time
        coding is not at play, it is assumed that the images are in order
        of importance. It has one required attribute and three optional
        attributes.

        media:thumbnail has the following fields:
        - *url* should specify the direct URL to the media object.
        - *height* height of the media object.
        - *width* width of the media object.
        - *time* specifies the time offset in relation to the media object.

        :param thumbnail: Dictionary or list of dictionaries with thumbnail
                          data.
        :param replace: Add or replace old data.
        :param group: Media group to put this content in.

        :returns: The media thumbnail tag.
        '''
        # Handle kwargs
        if thumbnail is None and kwargs:
            thumbnail = kwargs
        # Handle new data
        if thumbnail is not None:
            # Reset data if we want to replace them
            if replace or self.__media_thumbnail is None:
                self.__media_thumbnail = []
            # Ensure list
            if not isinstance(thumbnail, list):
                thumbnail = [thumbnail]
            # Define media group
            for t in thumbnail:
                t['group'] = t.get('group', group)
            self.__media_thumbnail += ensure_format(
                    thumbnail,
                    set(['url', 'height', 'width', 'time', 'group']),
                    set(['url', 'group']))
        return self.__media_thumbnail
コード例 #11
0
ファイル: feed.py プロジェクト: ngulden/python-feedgen
	def category(self, category=None, replace=False, **kwargs):
		'''Get or set categories that the feed belongs to.

		This method can be called with:

		- the fields of a category as keyword arguments
		- the fields of a category as a dictionary
		- a list of dictionaries containing the category fields

		A categories has the following fields:

		- *term* identifies the category
		- *scheme* identifies the categorization scheme via a URI.
		- *label* provides a human-readable label for display

		If a label is present it is used for the RSS feeds. Otherwise the term is
		used. The scheme is used for the domain attribute in RSS.

		:param link:    Dict or list of dicts with data.
		:param replace: Add or replace old data.
		:returns: List of category data.
		'''
		if category is None and kwargs:
			category = kwargs
		if not category is None:
			if replace or self.__atom_category is None:
				self.__atom_category = []
			self.__atom_category += ensure_format( 
					category, 
					set(['term', 'scheme', 'label']),
					set(['term']) )
			# Map the ATOM categories to RSS categories. Use the atom:label as
			# name or if not present the atom:term. The atom:schema is the
			# rss:domain.
			self.__rss_category = []
			for cat in self.__atom_category:
				rss_cat = {}
				rss_cat['value'] = cat['label'] if cat.get('label') else cat['term']
				if cat.get('schema'):
					rss_cat['domain'] = cat['schema']
				self.__rss_category.append( rss_cat )
		return self.__atom_category
コード例 #12
0
ファイル: podcast.py プロジェクト: xaxa/python-feedgen
	def itunes_category(self, itunes_category=None, replace=False, **kwargs):
		'''Get or set the ITunes category which appears in the category column
		and in iTunes Store Browser.

		The (sub-)category has to be one from the values defined at
		http://www.apple.com/itunes/podcasts/specs.html#categories

		This method can be called with:
		- the fields of an itunes_category as keyword arguments
		- the fields of an itunes_category as a dictionary
		- a list of dictionaries containing the itunes_category fields

		An itunes_category has the following fields:
		- *cat* name for a category.
		- *sub* name for a subcategory, child of category

		If a podcast has more than one subcategory from the same category, the 
		category is called more than once.
		Like: [{"cat":"Arts","sub":"Design"},{"cat":"Arts","sub":"Food"}]
		The code will be:
		<itunes:category text="Arts">
	    	<itunes:category text="Design"/>
	    	<itunes:category text="Food"/>
	    </itunes:category>


		:param itunes_category: Dictionary or list of dictionaries with itunes_category data.
		:param replace: Add or replace old data.
		:returns: List of itunes_categories as dictionaries.
		'''
		if itunes_category is None and kwargs:
			itunes_category = kwargs
		if not itunes_category is None:
			if replace or self.__itunes_category is None:
				self.__itunes_category = []
			self.__itunes_category += ensure_format( itunes_category,
					set(['cat', 'sub']), set(['cat']))
		return self.__itunes_category
コード例 #13
0
    def content(self, content=None, replace=False, group='default', **kwargs):
        '''Get or set media:content data.

        This method can be called with:
        - the fields of a media:content as keyword arguments
        - the fields of a media:content as a dictionary
        - a list of dictionaries containing the media:content fields

        <media:content> is a sub-element of either <item> or <media:group>.
        Media objects that are not the same content should not be included in
        the same <media:group> element. The sequence of these items implies
        the order of presentation. While many of the attributes appear to be
        audio/video specific, this element can be used to publish any type
        of media. It contains 14 attributes, most of which are optional.

        media:content has the following fields:
        - *url* should specify the direct URL to the media object.
        - *fileSize* number of bytes of the media object.
        - *type* standard MIME type of the object.
        - *medium* type of object (image | audio | video | document |
          executable).
        - *isDefault* determines if this is the default object.
        - *expression* determines if the object is a sample or the full version
          of the object, or even if it is a continuous stream (sample | full |
          nonstop).
        - *bitrate* kilobits per second rate of media.
        - *framerate* number of frames per second for the media object.
        - *samplingrate* number of samples per second taken to create the media
          object. It is expressed in thousands of samples per second (kHz).
        - *channels* number of audio channels in the media object.
        - *duration* number of seconds the media object plays.
        - *height* height of the media object.
        - *width* width of the media object.
        - *lang* is the primary language encapsulated in the media object.

        :param content: Dictionary or list of dictionaries with content data.
        :param replace: Add or replace old data.
        :param group: Media group to put this content in.

        :returns: The media content tag.
        '''
        # Handle kwargs
        if content is None and kwargs:
            content = kwargs
        # Handle new data
        if content is not None:
            # Reset data if we want to replace them
            if replace or self.__media_content is None:
                self.__media_content = []
            # Ensure list
            if not isinstance(content, list):
                content = [content]
            # define media group
            for c in content:
                c['group'] = c.get('group', group)
            self.__media_content += ensure_format(
                content,
                set([
                    'url', 'fileSize', 'type', 'medium', 'isDefault',
                    'expression', 'bitrate', 'framerate', 'samplingrate',
                    'channels', 'duration', 'height', 'width', 'lang', 'group'
                ]), set(['url', 'group']))
        return self.__media_content
コード例 #14
0
ファイル: podcast.py プロジェクト: lkiesow/python-feedgen
    def itunes_category(self, itunes_category=None, replace=False, **kwargs):
        '''Get or set the ITunes category which appears in the category column
        and in iTunes Store Browser.

        The (sub-)category has to be one from the values defined at
        http://www.apple.com/itunes/podcasts/specs.html#categories

        This method can be called with:

        - the fields of an itunes_category as keyword arguments
        - the fields of an itunes_category as a dictionary
        - a list of dictionaries containing the itunes_category fields

        An itunes_category has the following fields:

        - *cat* name for a category.
        - *sub* name for a subcategory, child of category

        If a podcast has more than one subcategory from the same category, the
        category is called more than once.

        Likei the parameter::

            [{"cat":"Arts","sub":"Design"},{"cat":"Arts","sub":"Food"}]

        …would become::

            <itunes:category text="Arts">
                <itunes:category text="Design"/>
                <itunes:category text="Food"/>
            </itunes:category>


        :param itunes_category: Dictionary or list of dictionaries with
                                itunes_category data.
        :param replace: Add or replace old data.
        :returns: List of itunes_categories as dictionaries.

        ---

        **Important note about deprecated parameter syntax:** Old version of
        the feedgen did only support one category plus one subcategory which
        would be passed to this ducntion as first two parameters. For
        compatibility reasons, this still works but should not be used any may
        be removed at any time.
        '''
        # Ensure old API still works for now. Note that the API is deprecated
        # and this fallback may be removed at any time.
        if isinstance(itunes_category, string_types):
            itunes_category = {'cat': itunes_category}
            if replace:
                itunes_category['sub'] = replace
            replace = True
        if itunes_category is None and kwargs:
            itunes_category = kwargs
        if itunes_category is not None:
            if replace or self.__itunes_category is None:
                self.__itunes_category = []
            self.__itunes_category += ensure_format(itunes_category,
                                                    set(['cat', 'sub']),
                                                    set(['cat']))
        return self.__itunes_category
コード例 #15
0
	def link(self, link=None, replace=False, **kwargs):
		'''Get or set link data. An link element is a dict with the fields href,
		rel, type, hreflang, title, and length. Href is mandatory for ATOM.

		This method can be called with:
		- the fields of a link as keyword arguments
		- the fields of a link as a dictionary
		- a list of dictionaries containing the link fields

		A link has the following fields:

		- *href* is the URI of the referenced resource (typically a Web page)
		- *rel* contains a single link relationship type. It can be a full URI,
		  or one of the following predefined values (default=alternate):

			- *alternate* an alternate representation of the entry or feed, for
			  example a permalink to the html version of the entry, or the front
			  page of the weblog.
			- *enclosure* a related resource which is potentially large in size
			  and might require special handling, for example an audio or video
			  recording.
			- *related* an document related to the entry or feed.
			- *self* the feed itself.
			- *via* the source of the information provided in the entry.

		- *type* indicates the media type of the resource.
		- *hreflang* indicates the language of the referenced resource.
		- *title* human readable information about the link, typically for
		  display purposes.
		- *length* the length of the resource, in bytes.

		RSS only supports one link with URL only.

		:param link:    Dict or list of dicts with data.
		:param replace: Add or replace old data.

		Example::

			>>> feedgen.link( href='http://example.com/', rel='self')
			[{'href':'http://example.com/', 'rel':'self'}]

		'''
		if link is None and kwargs:
			link = kwargs
		if not link is None:
			if replace or self.__atom_link is None:
				self.__atom_link = []
			self.__atom_link += ensure_format( link,
					set(['href', 'rel', 'type', 'hreflang', 'title', 'length']),
					set(['href']),
					{'rel': [
						'about', 'alternate', 'appendix', 'archives', 'author', 'bookmark',
						'canonical', 'chapter', 'collection', 'contents', 'copyright', 'create-form',
						'current', 'derivedfrom', 'describedby', 'describes', 'disclosure',
						'duplicate', 'edit', 'edit-form', 'edit-media', 'enclosure', 'first', 'glossary',
						'help', 'hosts', 'hub', 'icon', 'index', 'item', 'last', 'latest-version', 'license',
						'lrdd', 'memento', 'monitor', 'monitor-group', 'next', 'next-archive', 'nofollow',
						'noreferrer', 'original', 'payment', 'predecessor-version', 'prefetch', 'prev', 'preview',
						'previous', 'prev-archive', 'privacy-policy', 'profile', 'related', 'replies', 'search',
						'section', 'self', 'service', 'start', 'stylesheet', 'subsection', 'successor-version',
						'tag', 'terms-of-service', 'timegate', 'timemap', 'type', 'up', 'version-history', 'via',
						'working-copy', 'working-copy-of'
					]})
			# RSS only needs one URL. We use the first link for RSS:
			if len(self.__atom_link) > 0:
				self.__rss_link = self.__atom_link[-1]['href']
		# return the set with more information (atom)
		return self.__atom_link
コード例 #16
0
ファイル: entry.py プロジェクト: lkiesow/python-feedgen
    def link(self, link=None, replace=False, **kwargs):
        '''Get or set link data. An link element is a dict with the fields
        href, rel, type, hreflang, title, and length. Href is mandatory for
        ATOM.

        This method can be called with:
        - the fields of a link as keyword arguments
        - the fields of a link as a dictionary
        - a list of dictionaries containing the link fields

        A link has the following fields:

        - *href* is the URI of the referenced resource (typically a Web page)
        - *rel* contains a single link relationship type. It can be a full URI,
          or one of the following predefined values (default=alternate):

            - *alternate* an alternate representation of the entry or feed, for
              example a permalink to the html version of the entry, or the
              front page of the weblog.
            - *enclosure* a related resource which is potentially large in size
              and might require special handling, for example an audio or video
              recording.
            - *related* an document related to the entry or feed.
            - *self* the feed itself.
            - *via* the source of the information provided in the entry.

        - *type* indicates the media type of the resource.
        - *hreflang* indicates the language of the referenced resource.
        - *title* human readable information about the link, typically for
          display purposes.
        - *length* the length of the resource, in bytes.

        RSS only supports one link with nothing but a URL. So for the RSS link
        element the last link with rel=alternate is used.

        RSS also supports one enclusure element per entry which is covered by
        the link element in ATOM feed entries. So for the RSS enclusure element
        the last link with rel=enclosure is used.

        :param link:    Dict or list of dicts with data.
        :param replace: Add or replace old data.
        :returns: List of link data.
        '''
        if link is None and kwargs:
            link = kwargs
        if link is not None:
            if replace or self.__atom_link is None:
                self.__atom_link = []
            self.__atom_link += ensure_format(
                link,
                set(['href', 'rel', 'type', 'hreflang', 'title', 'length']),
                set(['href']),
                {'rel': ['alternate', 'enclosure', 'related', 'self', 'via']},
                {'rel': 'alternate'})
            # RSS only needs one URL. We use the first link for RSS:
            for l in self.__atom_link:
                if l.get('rel') == 'alternate':
                    self.__rss_link = l['href']
                elif l.get('rel') == 'enclosure':
                    self.__rss_enclosure = {'url': l['href']}
                    self.__rss_enclosure['type'] = l.get('type')
                    self.__rss_enclosure['length'] = l.get('length') or '0'
        # return the set with more information (atom)
        return self.__atom_link
コード例 #17
0
    def itunes_category(self, itunes_category=None, replace=False, **kwargs):
        '''Get or set the ITunes category which appears in the category column
        and in iTunes Store Browser.

        The (sub-)category has to be one from the values defined at
        http://www.apple.com/itunes/podcasts/specs.html#categories

        This method can be called with:

        - the fields of an itunes_category as keyword arguments
        - the fields of an itunes_category as a dictionary
        - a list of dictionaries containing the itunes_category fields

        An itunes_category has the following fields:

        - *cat* name for a category.
        - *sub* name for a subcategory, child of category

        If a podcast has more than one subcategory from the same category, the
        category is called more than once.

        Likei the parameter::

            [{"cat":"Arts","sub":"Design"},{"cat":"Arts","sub":"Food"}]

        …would become::

            <itunes:category text="Arts">
                <itunes:category text="Design"/>
                <itunes:category text="Food"/>
            </itunes:category>


        :param itunes_category: Dictionary or list of dictionaries with
                                itunes_category data.
        :param replace: Add or replace old data.
        :returns: List of itunes_categories as dictionaries.

        ---

        **Important note about deprecated parameter syntax:** Old version of
        the feedgen did only support one category plus one subcategory which
        would be passed to this ducntion as first two parameters. For
        compatibility reasons, this still works but should not be used any may
        be removed at any time.
        '''
        # Ensure old API still works for now. Note that the API is deprecated
        # and this fallback may be removed at any time.
        if isinstance(itunes_category, string_types):
            itunes_category = {'cat': itunes_category}
            if replace:
                itunes_category['sub'] = replace
            replace = True
        if itunes_category is None and kwargs:
            itunes_category = kwargs
        if itunes_category is not None:
            if replace or self.__itunes_category is None:
                self.__itunes_category = []
            self.__itunes_category += ensure_format(itunes_category,
                                                    set(['cat', 'sub']),
                                                    set(['cat']))
        return self.__itunes_category
コード例 #18
0
    def link(self, link=None, replace=False, **kwargs):
        '''Get or set link data. An link element is a dict with the fields
        href, rel, type, hreflang, title, and length. Href is mandatory for
        ATOM.

        This method can be called with:

        - the fields of a link as keyword arguments
        - the fields of a link as a dictionary
        - a list of dictionaries containing the link fields

        A link has the following fields:

        - *href* is the URI of the referenced resource (typically a Web page)
        - *rel* contains a single link relationship type. It can be a full URI,
          or one of the following predefined values (default=alternate):

            - *alternate* an alternate representation of the entry or feed, for
              example a permalink to the html version of the entry, or the
              front page of the weblog.
            - *enclosure* a related resource which is potentially large in size
              and might require special handling, for example an audio or video
              recording.
            - *related* an document related to the entry or feed.
            - *self* the feed itself.
            - *via* the source of the information provided in the entry.

        - *type* indicates the media type of the resource.
        - *hreflang* indicates the language of the referenced resource.
        - *title* human readable information about the link, typically for
          display purposes.
        - *length* the length of the resource, in bytes.

        RSS only supports one link with URL only.

        :param link:    Dict or list of dicts with data.
        :param replace: If old links are to be replaced (default: False)
        :returns:       Current set of link data

        Example::

            >>> feedgen.link( href='http://example.com/', rel='self')
            [{'href':'http://example.com/', 'rel':'self'}]

        '''
        if link is None and kwargs:
            link = kwargs
        if link is not None:
            if replace or self.__atom_link is None:
                self.__atom_link = []
            self.__atom_link += ensure_format(
                link,
                set(['href', 'rel', 'type', 'hreflang', 'title', 'length']),
                set(['href']), {
                    'rel': [
                        'about', 'alternate', 'appendix', 'archives', 'author',
                        'bookmark', 'canonical', 'chapter', 'collection',
                        'contents', 'copyright', 'create-form', 'current',
                        'derivedfrom', 'describedby', 'describes',
                        'disclosure', 'duplicate', 'edit', 'edit-form',
                        'edit-media', 'enclosure', 'first', 'glossary', 'help',
                        'hosts', 'hub', 'icon', 'index', 'item', 'last',
                        'latest-version', 'license', 'lrdd', 'memento',
                        'monitor', 'monitor-group', 'next', 'next-archive',
                        'nofollow', 'noreferrer', 'original', 'payment',
                        'predecessor-version', 'prefetch', 'prev', 'preview',
                        'previous', 'prev-archive', 'privacy-policy',
                        'profile', 'related', 'replies', 'search', 'section',
                        'self', 'service', 'start', 'stylesheet', 'subsection',
                        'successor-version', 'tag', 'terms-of-service',
                        'timegate', 'timemap', 'type', 'up', 'version-history',
                        'via', 'working-copy', 'working-copy-of'
                    ]
                })
            # RSS only needs one URL. We use the first link for RSS:
            if len(self.__atom_link) > 0:
                self.__rss_link = self.__atom_link[-1]['href']
        # return the set with more information (atom)
        return self.__atom_link
コード例 #19
0
ファイル: media.py プロジェクト: lkiesow/python-feedgen
    def content(self, content=None, replace=False, group='default', **kwargs):
        '''Get or set media:content data.

        This method can be called with:
        - the fields of a media:content as keyword arguments
        - the fields of a media:content as a dictionary
        - a list of dictionaries containing the media:content fields

        <media:content> is a sub-element of either <item> or <media:group>.
        Media objects that are not the same content should not be included in
        the same <media:group> element. The sequence of these items implies
        the order of presentation. While many of the attributes appear to be
        audio/video specific, this element can be used to publish any type
        of media. It contains 14 attributes, most of which are optional.

        media:content has the following fields:
        - *url* should specify the direct URL to the media object.
        - *fileSize* number of bytes of the media object.
        - *type* standard MIME type of the object.
        - *medium* type of object (image | audio | video | document |
          executable).
        - *isDefault* determines if this is the default object.
        - *expression* determines if the object is a sample or the full version
          of the object, or even if it is a continuous stream (sample | full |
          nonstop).
        - *bitrate* kilobits per second rate of media.
        - *framerate* number of frames per second for the media object.
        - *samplingrate* number of samples per second taken to create the media
          object. It is expressed in thousands of samples per second (kHz).
        - *channels* number of audio channels in the media object.
        - *duration* number of seconds the media object plays.
        - *height* height of the media object.
        - *width* width of the media object.
        - *lang* is the primary language encapsulated in the media object.

        :param content: Dictionary or list of dictionaries with content data.
        :param replace: Add or replace old data.
        :param group: Media group to put this content in.

        :returns: The media content tag.
        '''
        # Handle kwargs
        if content is None and kwargs:
            content = kwargs
        # Handle new data
        if content is not None:
            # Reset data if we want to replace them
            if replace or self.__media_content is None:
                self.__media_content = []
            # Ensure list
            if not isinstance(content, list):
                content = [content]
            # define media group
            for c in content:
                c['group'] = c.get('group', group)
            self.__media_content += ensure_format(
                    content,
                    set(['url', 'fileSize', 'type', 'medium', 'isDefault',
                         'expression', 'bitrate', 'framerate', 'samplingrate',
                         'channels', 'duration', 'height', 'width', 'lang',
                         'group']),
                    set(['url', 'group']))
        return self.__media_content