Is there any Generic RSS/ATOM generator in Python?

J

js

Hi,

I'm looking for RSS/ATOM generator I can use in Python.
I searched on pypi and the other places but I couldn't find any
options on this. (I found many parsers, though)
Is there any de-fact standard RSS/ATOM generator? (especially, I'd
like to create Atom's)
Do I have to do it myself from scratch?

Thanks in advance.
 
S

Stefan Behnel

js said:
I'm looking for RSS/ATOM generator I can use in Python.
I searched on pypi and the other places but I couldn't find any
options on this. (I found many parsers, though)
Is there any de-fact standard RSS/ATOM generator? (especially, I'd
like to create Atom's)
Do I have to do it myself from scratch?

Try googling for "python atom", gives me this as first hit:

http://www.imc.org/atom-syntax/mail-archive/msg18662.html

But since it's not that hard to generate XML in general, maybe these are also
worth another look:

http://blog.ianbicking.org/2007/08/02/atom-models/
http://codespeak.net/lxml/objectify.html#tree-generation-with-the-e-factory

Stefan
 
T

Terran Melconian

Is there any de-fact standard RSS/ATOM generator? (especially, I'd
like to create Atom's)
Do I have to do it myself from scratch?

I looked into similar issues about six months ago. My conclusion was
that generally XML generation libraries (unlike parsers) don't get
written, because there's little enough to them that it isn't seen as
worth doing, and that accepted practice is to just do it yourself.
 
T

Torsten Bronger

Hallöchen!

Terran said:
I looked into similar issues about six months ago. My conclusion
was that generally XML generation libraries (unlike parsers) don't
get written, because there's little enough to them that it isn't
seen as worth doing, and that accepted practice is to just do it
yourself.

Maybe I understand you wrongly but there *is* a general XML
generator with ElementTree. I wouldn't generate XML directly but
using ElementTree to generate Atom. I did it myself three months
ago and it was really trivial.

Tschö,
Torsten.
 
S

Stefan Behnel

Torsten said:
Maybe I understand you wrongly but there *is* a general XML
generator with ElementTree. I wouldn't generate XML directly but
using ElementTree to generate Atom. I did it myself three months
ago and it was really trivial.

Actually, there's tons of XML generator packages (most of them single Python
modules), ElementTree itself and the "E factory" being only two of them.

Stefan
 
T

Torsten Bronger

Hallöchen!

Stefan said:
Torsten said:
Terran Melconian writes:

[...]

Maybe I understand you wrongly but there *is* a general XML
generator with ElementTree. I wouldn't generate XML directly but
using ElementTree to generate Atom. I did it myself three months
ago and it was really trivial.

Actually, there's tons of XML generator packages (most of them
single Python modules), ElementTree itself and the "E factory"
being only two of them.

I mentioned ElementTree because in my opinion, it is the only sane
XML generator in the standard lib.

Tschö,
Torsten.
 
S

Stefan Behnel

Torsten said:
Excerpt from my code:

root = ElementTree.Element("feed", xmlns="http://www.w3.org/2005/Atom")
ElementTree.SubElement(root, "id").text = self.id
ElementTree.SubElement(root, "title").text = self.title
ElementTree.SubElement(root, "updated").text = format_time(self.updated)

Look at the bottom of this page for an RSS example using the "E factory":

http://effbot.org/zone/element-builder.htm

I find it much more readable than the above code, especially if you use the
version that comes with lxml.objectify, which has better support for
namespaces and data types:

http://codespeak.net/lxml/objectify.html#tree-generation-with-the-e-factory

Stefan
 
T

Torsten Bronger

Hallöchen!

Stefan said:
Torsten said:
[...]

Excerpt from my code:

root = ElementTree.Element("feed", xmlns="http://www.w3.org/2005/Atom")
ElementTree.SubElement(root, "id").text = self.id
ElementTree.SubElement(root, "title").text = self.title
ElementTree.SubElement(root, "updated").text = format_time(self.updated)

Look at the bottom of this page for an RSS example using the "E factory":

http://effbot.org/zone/element-builder.htm

I find it much more readable than the above code, especially if you use the
version that comes with lxml.objectify, which has better support for
namespaces and data types:

http://codespeak.net/lxml/objectify.html#tree-generation-with-the-e-factory

If you have more complex tasks, all this may be true; however,
generating Atom is just *so* simple that I prefer the version which
works without tweaking and further dependencies.

Tschö,
Torsten.
 
S

Stefan Behnel

Torsten said:
Stefan said:
Torsten said:
[...]

Excerpt from my code:

root = ElementTree.Element("feed", xmlns="http://www.w3.org/2005/Atom")
ElementTree.SubElement(root, "id").text = self.id
ElementTree.SubElement(root, "title").text = self.title
ElementTree.SubElement(root, "updated").text = format_time(self.updated)

Look at the bottom of this page for an RSS example using the "E factory":

http://effbot.org/zone/element-builder.htm
[...]
If you have more complex tasks, all this may be true; however,
generating Atom is just *so* simple that I prefer the version which
works without tweaking and further dependencies.

The E factory is a small module with one main class. Adding that to your code
base doesn't give you any dependencies...

Stefan
 
J

js

Great...
I guess I should have learned more about ElementTree.
In anyway, Thanks all. You all convinced me, really.
 
T

Torsten Bronger

Hallöchen!

Stefan said:
[...]

The E factory is a small module with one main class. Adding that
to your code base doesn't give you any dependencies...

Yes, but just for creating five elements? ;-)

Tschö,
Torsten.
 
C

Christopher Arndt

I'm looking for RSS/ATOM generator I can use in Python.
I searched on pypi and the other places but I couldn't find any
options on this. (I found many parsers, though)
Is there any de-fact standard RSS/ATOM generator? (especially, I'd
like to create Atom's)
Do I have to do it myself from scratch?

You didn't specify your use case very much. If you just want to add
support for generating Atom/RSS feeds to your app and the format (i.e.
which elements and attributes are used) isn't too dynamic, you could
just an XML-templating language like Kid or Genshi.

The feed generator included in TurboGears uses this approach. I
recently packaged this as a separate module:

http://chrisarndt.de/projects/turbofeeds/

The module still only makes sense in a TurboGears context but you may
want to look at the Kid templates used, they could be used by any app
that wants to generate Atom/RSS:

http://trac.turbogears.org/browser/projects/TurboFeeds/trunk/turbofeeds/templates

Chris
 

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

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top