473,394 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

rss feed generation

I'm looking for suggestions on how to approach generating rss feed
..xml files using python. What modules to people recommend I start
with?

Thanks!
Blake
Sep 9 '08 #1
4 1921
On Sep 10, 7:30*am, "Blake Garner" <trodemas...@gmail.comwrote:
I'm looking for suggestions on how to approach generating rss feed
.xml files using python. What modules to people recommend I start
with?
http://www.dalkescientific.com/Python/PyRSS2Gen.html
Sep 10 '08 #2
On Tue, Sep 9, 2008 at 9:35 PM, alex23 <wu*****@gmail.comwrote:
On Sep 10, 7:30 am, "Blake Garner" <trodemas...@gmail.comwrote:
>I'm looking for suggestions on how to approach generating rss feed
.xml files using python. What modules to people recommend I start
with?
pylons webhelpers makes a good work too.

[]'s
- Walter
Sep 12 '08 #3
Walter Cruz wrote:
On Tue, Sep 9, 2008 at 9:35 PM, alex23 <wu*****@gmail.comwrote:
>On Sep 10, 7:30 am, "Blake Garner" <trodemas...@gmail.comwrote:
>>I'm looking for suggestions on how to approach generating rss feed
.xml files using python. What modules to people recommend I start
with?
I just rolled something with ElementTree. No idea how it
stacks up against validity checks, but it seems to be
accepted by a couple of standard feed readers.

(sorry; longish code segment)

<code>
import os, sys
from datetime import datetime
try:
from xml.etree import cElementTree as ET
except ImportError:
from elementtree import ElementTree as ET

class Feed (object):

ENCODING = "utf-8"

def __init__ (self, title, link, description=None, author=None, updated_on=None):
self.title = title
self.link = link
self.description = description
self.author = author
self.updated_on = updated_on or datetime.now ()
self.entries = []

def add_entry (self, title, link, content, summary=None, id=None, updated_on=None):
self.entries.append (
dict (
title=title,
link=link,
content=content,
summary=summary,
id=id or link,
updated_on=updated_on or datetime.now ()
)
)

def write_rss (self, ofile=sys.stdout, encoding=ENCODING):
rss = ET.Element ("rss", version="2.0")
channel = ET.SubElement (rss, "channel")
ET.SubElement (channel, "title").text = self.title
ET.SubElement (channel, "link").text = self.link
ET.SubElement (channel, "description").text = self.description

for entry in self.entries:
item = ET.SubElement (channel, "item")
ET.SubElement (item, "title").text = entry['title']
ET.SubElement (item, "link").text = entry['link']
ET.SubElement (item, "guid").text = entry['id']
ET.SubElement (item, "description").text = entry['content']

ET.ElementTree (rss).write (ofile, encoding=encoding)

def write_atom (self, ofile=sys.stdout, encoding=ENCODING):
feed = ET.Element ("feed")
ET.SubElement (feed, "title", type="text").text = self.title
ET.SubElement (feed, "link", rel="self", href=self.link)
if self.description:
ET.SubElement (feed, "subtitle", type="text").text = self.description
if self.author:
name, email = self.author
author = ET.SubElement (feed, "author")
ET.SubElement (author, "name").text = name
ET.SubElement (author, "email").text = email
ET.SubElement (feed, "updated").text = self.updated_on.isoformat ()

for entry in self.entries:
e = ET.SubElement (feed, "entry")
ET.SubElement (e, "title").text = entry['title']
ET.SubElement (e, "link", href=entry['link'])
ET.SubElement (e, "id").text = entry['id']
ET.SubElement (e, "updated").text = entry['updated_on'].isoformat ()
if entry['summary']:
ET.SubElement (e, "summary").text = entry['summary']
ET.SubElement (e, "content", type="html").text = "<![CDATA[%s]]>" % entry['content']

ET.ElementTree (feed).write (ofile, encoding=encoding)

if __name__ == '__main__':
feed = Feed ("Feed for example.org", "http://example.org", author=("Tim Golden", "ti*@example.org"))
for i in range (5):
feed.add_entry ("Entry %d" % i, "http://example.org/entry/%d" % i, "Contents for entry %d" % i, id="entry#%d" % i)
feed.write_atom (open ("feed.atom.xml", "w"), "iso-8859-1")
feed.write_rss (open ("feed.rss.xml", "w"), "iso-8859-1")

</code>

TJG
Sep 12 '08 #4
Tim Golden wrote:
Walter Cruz wrote:
>On Tue, Sep 9, 2008 at 9:35 PM, alex23 <wu*****@gmail.comwrote:
>>On Sep 10, 7:30 am, "Blake Garner" <trodemas...@gmail.comwrote:
I'm looking for suggestions on how to approach generating rss feed
.xml files using python. What modules to people recommend I start
with?

I just rolled something with ElementTree. No idea how it
stacks up against validity checks, but it seems to be
accepted by a couple of standard feed readers.

[... snip messy code ...]

Well that didn't come out very well. If anyone's interested,
I've dropped the module here:

http://timgolden.me.uk/python/downloads/feeder.py

TJG
Sep 12 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
0
by: Rasmus Fogh | last post by:
Someone raised the question of automatic code generation a few weeks back. And yes, we (CCPN) are using automatic Python code generation in a major way. Basically we are making data models in...
1
by: Steve | last post by:
I have a script that has been modified from one that I found on the internet to display RSS feeds in html. The script works fine for most RSS feeds but there are a number that it fails on with the...
6
by: affiliateian | last post by:
Total newbie here for this so please be patient. We manually update our XML feed when we publish an article on our website. Can we add a javascript tracking pixel (from phpadsnew) into the XML...
4
by: Florian Lindner | last post by:
Hello, I'm looking for python RSS feed parser library. Feedparser http://feedparser.org/ does not seem to maintained anymore. What alternatives are recommendable? Thanks, Florian
5
by: Ed Flecko | last post by:
Hi folks, I'm trying to figure out this whole RSS feed thing. I've created my .xml file to use for my feed, and my browsers "recognize" that I have an RSS feed, and you can subscribe, etc., etc....
8
by: Greg C. | last post by:
I tried tackling this problem about 6 months ago, but after going almost completely insane I gave up, since my news feed seemed to display just fine anyways. However, in an effort to have my feeds...
10
by: bhass | last post by:
From my other post I am making a simple program that creates an RSS feed with Python. Now when I run my program so far, I get errors. It says "something is not defined". The word something is...
2
jamwil
by: jamwil | last post by:
What's up guys. I'm having some issues... I've created a method as part of my lifestreaming class which takes an rss feed, and puts the data into a database... It's fairly simple... Check...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.