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

  • Thread starter Steve R. Hastings
  • Start date
S

Steve R. Hastings

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.
 
U

uche.ogbuji

Steve said:
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.

FWIW, see also Sylvain Hellegouarch's atomixlib [1]. It's used in
production to generate and manage PlanetAtom [2][3].

[1] http://trac.defuze.org/browser/oss/atomixlib
[2] http://planetatom.net/
[3] http://copia.ogbuji.net/blog/2006-01-25/Planet_Ato
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,010
Latest member
MerrillEic

Latest Threads

Top