Documentation Update

Just updating a few minor bits of the documentation.
This commit is contained in:
Lars Kiesow 2020-01-25 22:09:52 +01:00
parent 771b45021b
commit e942a0839e
No known key found for this signature in database
GPG key ID: 5DAFE8D9C823CE73
2 changed files with 64 additions and 52 deletions

View file

@ -21,9 +21,9 @@ at license.bsd and license.lgpl.
More details about the project: More details about the project:
- Repository: https://github.com/lkiesow/python-feedgen - `Repository <https://github.com/lkiesow/python-feedgen>`_
- Documentation: https://lkiesow.github.io/python-feedgen/ - `Documentation <https://lkiesow.github.io/python-feedgen/>`_
- Python Package Index: https://pypi.python.org/pypi/feedgen/ - `Python Package Index <https://pypi.python.org/pypi/feedgen/>`_
------------ ------------
@ -50,18 +50,20 @@ Create a Feed
------------- -------------
To create a feed simply instantiate the FeedGenerator class and insert some To create a feed simply instantiate the FeedGenerator class and insert some
data:: data:
>>> from feedgen.feed import FeedGenerator .. code-block:: python
>>> fg = FeedGenerator()
>>> fg.id('http://lernfunk.de/media/654321') from feedgen.feed import FeedGenerator
>>> fg.title('Some Testfeed') fg = FeedGenerator()
>>> fg.author( {'name':'John Doe','email':'john@example.de'} ) fg.id('http://lernfunk.de/media/654321')
>>> fg.link( href='http://example.com', rel='alternate' ) fg.title('Some Testfeed')
>>> fg.logo('http://ex.com/logo.jpg') fg.author( {'name':'John Doe','email':'john@example.de'} )
>>> fg.subtitle('This is a cool feed!') fg.link( href='http://example.com', rel='alternate' )
>>> fg.link( href='http://larskiesow.de/test.atom', rel='self' ) fg.logo('http://ex.com/logo.jpg')
>>> fg.language('en') fg.subtitle('This is a cool feed!')
fg.link( href='http://larskiesow.de/test.atom', rel='self' )
fg.language('en')
Note that for the methods which set fields that can occur more than once in a Note that for the methods which set fields that can occur more than once in a
feed you can use all of the following ways to provide data: feed you can use all of the following ways to provide data:
@ -70,22 +72,26 @@ feed you can use all of the following ways to provide data:
- Provide the data for that element as dictionary - Provide the data for that element as dictionary
- Provide a list of dictionaries with the data for several elements - Provide a list of dictionaries with the data for several elements
Example:: Example:
>>> fg.contributor( name='John Doe', email='jdoe@example.com' ) .. code-block:: python
>>> fg.contributor({'name':'John Doe', 'email':'jdoe@example.com'})
>>> fg.contributor([{'name':'John Doe', 'email':'jdoe@example.com'}, ...]) fg.contributor( name='John Doe', email='jdoe@example.com' )
fg.contributor({'name':'John Doe', 'email':'jdoe@example.com'})
fg.contributor([{'name':'John Doe', 'email':'jdoe@example.com'}, ...])
----------------- -----------------
Generate the Feed Generate the Feed
----------------- -----------------
After that you can generate both RSS or ATOM by calling the respective method:: After that you can generate both RSS or ATOM by calling the respective method:
>>> atomfeed = fg.atom_str(pretty=True) # Get the ATOM feed as string .. code-block:: python
>>> rssfeed = fg.rss_str(pretty=True) # Get the RSS feed as string
>>> fg.atom_file('atom.xml') # Write the ATOM feed to a file atomfeed = fg.atom_str(pretty=True) # Get the ATOM feed as string
>>> fg.rss_file('rss.xml') # Write the RSS feed to a file rssfeed = fg.rss_str(pretty=True) # Get the RSS feed as string
fg.atom_file('atom.xml') # Write the ATOM feed to a file
fg.rss_file('rss.xml') # Write the RSS feed to a file
---------------- ----------------
@ -95,31 +101,35 @@ Add Feed Entries
To add entries (items) to a feed you need to create new FeedEntry objects and To add entries (items) to a feed you need to create new FeedEntry objects and
append them to the list of entries in the FeedGenerator. The most convenient append them to the list of entries in the FeedGenerator. The most convenient
way to go is to use the FeedGenerator itself for the instantiation of the way to go is to use the FeedGenerator itself for the instantiation of the
FeedEntry object:: FeedEntry object:
>>> fe = fg.add_entry() .. code-block:: python
>>> fe.id('http://lernfunk.de/media/654321/1')
>>> fe.title('The First Episode')
>>> fe.link(href="http://lernfunk.de/feed")
The FeedGenerators method `add_entry(...)` without argument provides will fe = fg.add_entry()
automatically generate a new FeedEntry object, append it to the feeds internal fe.id('http://lernfunk.de/media/654321/1')
list of entries and return it, so that additional data can be added. fe.title('The First Episode')
fe.link(href="http://lernfunk.de/feed")
The FeedGenerator's method `add_entry(...)` will generate a new FeedEntry
object, automatically append it to the feeds internal list of entries and
return it, so that additional data can be added.
---------- ----------
Extensions Extensions
---------- ----------
The FeedGenerator supports extension to include additional data into the XML The FeedGenerator supports extensions to include additional data into the XML
structure of the feeds. Extensions can be loaded like this:: structure of the feeds. Extensions can be loaded like this:
>>> fg.load_extension('someext', atom=True, rss=True) .. code-block:: python
This will try to load the extension “someext” from the file `ext/someext.py`. fg.load_extension('someext', atom=True, rss=True)
It is required that `someext.py` contains a class named “SomextExtension” which
is required to have at least the two methods `extend_rss(...)` and This example would try to load the extension “someext” from the file
`extend_atom(...)`. Although not required, it is strongly suggested to use `ext/someext.py`. It is required that `someext.py` contains a class named
`BaseExtension` from `ext/base.py` as superclass. “SomextExtension” which is required to have at least the two methods
`extend_rss(...)` and `extend_atom(...)`. Although not required, it is strongly
suggested to use `BaseExtension` from `ext/base.py` as superclass.
`load_extension('someext', ...)` will also try to load a class named `load_extension('someext', ...)` will also try to load a class named
“SomextEntryExtension” for every entry of the feed. This class can be located “SomextEntryExtension” for every entry of the feed. This class can be located
@ -127,7 +137,7 @@ either in the same file as SomextExtension or in `ext/someext_entry.py` which
is suggested especially for large extensions. is suggested especially for large extensions.
The parameters `atom` and `rss` control if the extension is used for ATOM and The parameters `atom` and `rss` control if the extension is used for ATOM and
RSS feeds, respectively. The default value for both parameters is `true` RSS feeds respectively. The default value for both parameters is `True`,
meaning the extension is used for both kinds of feeds. meaning the extension is used for both kinds of feeds.
**Example: Producing a Podcast** **Example: Producing a Podcast**
@ -135,22 +145,24 @@ meaning the extension is used for both kinds of feeds.
One extension already provided is the podcast extension. A podcast is an RSS One extension already provided is the podcast extension. A podcast is an RSS
feed with some additional elements for ITunes. feed with some additional elements for ITunes.
To produce a podcast simply load the `podcast` extension:: To produce a podcast simply load the `podcast` extension:
>>> from feedgen.feed import FeedGenerator .. code-block:: python
>>> fg = FeedGenerator()
>>> fg.load_extension('podcast') from feedgen.feed import FeedGenerator
fg = FeedGenerator()
fg.load_extension('podcast')
... ...
>>> fg.podcast.itunes_category('Technology', 'Podcasting') fg.podcast.itunes_category('Technology', 'Podcasting')
... ...
>>> fe = fg.add_entry() fe = fg.add_entry()
>>> fe.id('http://lernfunk.de/media/654321/1/file.mp3') fe.id('http://lernfunk.de/media/654321/1/file.mp3')
>>> fe.title('The First Episode') fe.title('The First Episode')
>>> fe.description('Enjoy our first episode.') fe.description('Enjoy our first episode.')
>>> fe.enclosure('http://lernfunk.de/media/654321/1/file.mp3', 0, 'audio/mpeg') fe.enclosure('http://lernfunk.de/media/654321/1/file.mp3', 0, 'audio/mpeg')
... ...
>>> fg.rss_str(pretty=True) fg.rss_str(pretty=True)
>>> fg.rss_file('podcast.xml') fg.rss_file('podcast.xml')
If the FeedGenerator class is used to load an extension, it is automatically If the FeedGenerator class is used to load an extension, it is automatically
loaded for every feed entry as well. You can, however, load an extension for a loaded for every feed entry as well. You can, however, load an extension for a