?

Log in

A stan dialect for generating RSS feeds. - David Reid [entries|archive|friends|userinfo]
David Reid

[ website | dreid.org ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

A stan dialect for generating RSS feeds. [May. 28th, 2004|01:35 am]
David Reid
[Current Mood |geekygeeky]

Today I was in the shower, and it occured to me how EASY it’d be to implement something I’d been thinking about for a while. A stan dialect for generating RSS feeds. If nothing else, it saves on typing. :)

For those of you not “in-the-know” stan is a pure python syntax for generating xml typically used for html by nevow. stan is part of nevow and a typical stan expression looks something like this.

html[
	head[
		title[“Foo”],
	],
	body[
		h1(align=“center”)[“Bar”]
	]
]


But like I said, stan is great for generating ANY XML. So i looked up the RSS 2.0 spec and got to hacking. With web applications these days particularly blogs and the like, the system is useless unless you generate RSS feeds. So I wrote a stan dialect. The source is available temporarily here. Here’s an example of the RSS stan dialect.

rss(version=“2.0”)[
	channel[
		title[“My Stan Generated RSS Feed”],
		link[“http://dreid.org/rss.py”],
		description[“An example RSS feed generated by a stan rss dialect.”],
		item[
			title[“Woo a title”],
			pubDate[“Fri, 28 May 2004 01:29:00 PST”]
			description[“An example item”]
		]
	]
]


Now that’s all fine and dandy, you can use a very basic nevow.rend.Page to render that as html. Or I hear rumors of lore+stan integration.

I also wrote an RssPage to accompany the stan dialect. It’s very simple ... all keyword args passed to it are assumed to be channel sub-elements (put inside the channel tag).
There is also a special keyword argument called “items” which is a list of dicts corresponding to item entries. All keys in the items dicts are assumed to be valid item sub-elements and are handled as such. RssPage is kind of hacky at this point ... but it shows the flexibility of using stan to generate the RSS Feeds. Here is a very basic usage example right out of the rss.py.

    items = [
        {‘title’: “Test Item #1”,
         ‘description’: “this is the 1st test item for the stan rss dialect rsspage”, 
         ‘pubDate’: “Sun, 29 Sep 2002 19:59:01 GMT”}, 
        {‘title’: “Test Item #2”,
         ‘description’: “this is the 2nd test item for the stan rss dialect rsspage”, 
         ‘pubDate’: “Sun, 28 Sep 2002 19:59:01 GMT”}, 
    ] 
    page = RssPage(
        title=“Test”, 
        link=“http://test/”, 
        description=“test of the stan rss dialect and RssPage”,
        items=items)


And the output. (Cleaned up to prevent sidescrolling madness)

<rss version=“2.0”>
	<channel>
		<link>http://test/</link>
		<description>test of the stan rss dialect and RssPage</description>
		<title>Test</title>
		<item>
			<description>this is the 1st test item for the stan rss dialect rsspage</description>
			<pubDate>Sun, 29 Sep 2002 19:59:01 GMT</pubDate>
			<title>Test Item #1</title>
		</item>
		<item>
			<description>this is the 2nd test item for the stan rss dialect rsspage</description>
			<pubDate>Sun, 28 Sep 2002 19:59:01 GMT</pubDate>
			<title>Test Item #2</title>
			</item>
	</channel>
</rss>


Woo isn’t that cool?
LinkReply

Comments:
From: puzzlement
2004-05-28 08:49 am (UTC)
Backwards is currently doing something like this (using datetime for dates though and some other changes), in fact I'm rather pleased with its feature set. However, I don't get to run it yet :(
(Reply) (Thread)
From: fzzzy
2004-05-28 03:43 pm (UTC)

Awesome

Man, that is so awesome. Horray!
(Reply) (Thread)
[User Picture]From: anarkystic
2004-05-28 07:45 pm (UTC)
it's a cool idea, but when would you ever be typing out an RSS feed?
(Reply) (Thread)
From: (Anonymous)
2004-05-29 04:23 pm (UTC)
I still don't understand how this presents a clear benefit over htmlfile or xmlfile, which can also generate RSS feeds. :P

mesozoic (http://mesozoic.geecs.org/)
(Reply) (Thread)