# $Id: $
# quixatom - Quixote PTL for Atom feed generation
from quixote import get_response, redirect
from quixote.directory import Directory
class FeedSource(object):
def get_entries(self):
return
def get_updated(self):
return
class Entry(object):
pass
class FeedXml(Directory):
_q_exports = ['']
xmlns = 'http://www.w3.org/2005/Atom'
def __init__(self, title, link, author_name, feed_id, feed_source):
self.title = title
self.link = link
self.author_name = author_name
self.feed_id = feed_id
self.feed_source = feed_source
def _q_index(self):
get_response().set_header('Content-Type', 'text/xml')
return self.feed_xml()
def feed_xml [html] (self):
'<?xml version="1.0"?>'
'<feed xmlns="%s">' % self.xmlns
'<title>%s</title>' % self.title
'<link href="%s"/>' % self.link
'<updated>%s</updated>' % self.feed_source.get_updated()
'<author><name>%s</name></author>' % self.author_name
'<id>%s</id>' % self.feed_id
for entry in self.feed_source.get_entries():
'<entry>'
'<title>%s</title>' % entry.title
'<link href="%s"/>' % entry.link
'<id>%s</id>' % entry.id
'<updated>%s</updated>' % entry.updated
'<summary>%s</summary>' % entry.summary
'</entry>'
'</feed>'
class SampleFeedSource(FeedSource):
def get_entries(self):
for d in [{'title': 'The title',
'link': 'http://link.tld',
'id': 'urn:link.tld',
'updated': '2003-12-13T18:30:02Z',
'summary': 'Summary for this entry'}]:
e = Entry()
for k,v in d.items():
setattr(e, k, v)
yield e
def get_last_updated(self):
return '2003-12-13T18:30:02Z'
def sample_feed():
return FeedXml('Sample quixatom Feed', 'http://www.cafepy.com/quixote_extras',
'Shalabh Chaturvedi', 'urn:cafepy.com:quixatom', SampleFeedSource())