Announcing atomfeed.py, xmlelements.py, and feedutils.py

Steve R. Hastings steve at hastings.org
Wed Mar 8 02:22:03 CET 2006


I have written some Python library modules to help with creating Atom
syndication feeds.  Originally, I had a single module called "PyAtom"; now
I have split it up into three modules: xmlelements.py, atomfeed.py, and
feedutils.py.

You can download these modules from here:

http://home.blarg.net/~steveha/atomfeed-0.5.0.tar.gz



I wrote these because I wanted a really easy, Pythonic way to create Atom
syndication feeds.  Here is a bit of sample code from the self-test at the
end of atomfeed.py:

-- cut here -- cut here -- cut here -- cut here -- cut here --
    # Test: generate the "Atom-Powered Robots Run Amok" example
    #
    # Note: the original had some of the XML declarations in
    # a different order than atomfeed puts them.  I swapped around
    # the lines here so they would match the atomfeed order.  Other
    # than that, this is the example from:
    #
    # http://www.atomenabled.org/developers/syndication/#sampleFeed

    s_example = """\
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Example Feed</title>
    <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
    <updated>2003-12-13T18:30:02Z</updated>
    <author>
        <name>John Doe</name>
    </author>
    <link href="http://example.org/"/>
    <entry>
        <title>Atom-Powered Robots Run Amok</title>
        <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
        <updated>2003-12-13T18:30:02Z</updated>
        <link href="http://example.org/2003/12/13/atom03"/>
        <summary>Some text.</summary>
    </entry>
</feed>"""

    xmldoc, feed = new_xmldoc_feed()

    feed.title = "Example Feed"
    feed.id = "urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"
    feed.updated = "2003-12-13T18:30:02Z"

    link = Link("http://example.org/")
    feed.links.append(link)

    author = Author("John Doe")
    feed.authors.append(author)


    entry = Entry()
    feed.entries.append(entry)
    entry.id = "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"
    entry.title = "Atom-Powered Robots Run Amok"
    entry.updated = "2003-12-13T18:30:02Z"
    entry.summary = "Some text."

    link = Link("http://example.org/2003/12/13/atom03")
    entry.links.append(link)


    s = str(xmldoc)
    if s_example != s:
        failed_tests += 1
        print "test case failed:"
        print "The generated XML doesn't match the example.  diff follows:"
        print diff(s_example, s)
-- cut here -- cut here -- cut here -- cut here -- cut here --


I welcome any feedback on these.
-- 
Steve R. Hastings    "Vita est"
steve at hastings.org    http://www.blarg.net/~steveha




More information about the Python-list mailing list