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.
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
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.
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.
Tschö,
Torsten.
--
Torsten Bronger, aquisgrana, europa vetus
Jabber ID: bro...@jabber.org
(See http://ime.webhop.org for further contact info.)
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
On Mon, Feb 11, 2008 at 3:47 PM, js <ebg...@gmail.com> wrote:
> 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?
You can look at PyRSS2Gen which works fine for me :
http://www.dalkescientific.com/Python/PyRSS2Gen.html
But it only works with RSS2.
Bye,
CanariX
>
> Thanks in advance.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Stefan Behnel writes:
> Torsten Bronger wrote:
>
>> 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.
js writes:
> Trivial?
> More than XML::Atom::Feed?
> http://search.cpan.org/~miyagawa/XML-Atom-0.28/lib/XML/Atom/Feed.pm
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
Stefan Behnel writes:
> Torsten Bronger wrote:
>
>> [...]
>>
>> 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.
The E factory is a small module with one main class. Adding that to your code
base doesn't give you any dependencies...
Stefan
Stefan Behnel writes:
> [...]
>
> 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? ;-)
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