Better conversion of RSS feeds to Atom

This commit is contained in:
Sam Ruby 2006-09-05 21:57:56 -04:00
parent e726744438
commit 4dd8c2bca2
2 changed files with 26 additions and 5 deletions

View File

@ -87,14 +87,19 @@ def id(xentry, entry):
def links(xentry, entry): def links(xentry, entry):
""" copy links to the entry """ """ copy links to the entry """
if not entry.has_key('links'): return if not entry.has_key('links'):
entry['links'] = []
if entry.has_key('link'):
entry['links'].append({'rel':'alternate', 'href':entry.link})
xdoc = xentry.ownerDocument xdoc = xentry.ownerDocument
for link in entry.links: for link in entry.links:
if not 'href' in link.keys(): continue if not 'href' in link.keys(): continue
xlink = xdoc.createElement('link') xlink = xdoc.createElement('link')
xlink.setAttribute('type', link.get('type',None)) xlink.setAttribute('href', link.get('href'))
xlink.setAttribute('href', link.href) if link.has_key('type'):
xlink.setAttribute('rel', link.get('rel',None)) xlink.setAttribute('type', link.get('type'))
if link.has_key('rel'):
xlink.setAttribute('rel', link.get('rel',None))
xentry.appendChild(xlink) xentry.appendChild(xlink)
def date(xentry, name, parsed): def date(xentry, name, parsed):
@ -165,7 +170,7 @@ def source(xsource, source, bozo):
content(xsource, 'subtitle', source.get('subtitle_detail',None), bozo) content(xsource, 'subtitle', source.get('subtitle_detail',None), bozo)
content(xsource, 'title', source.get('title_detail',None), bozo) content(xsource, 'title', source.get('title_detail',None), bozo)
date(xsource, 'updated', source.get('updated_parsed',None)) date(xsource, 'updated', source.get('updated_parsed',time.gmtime()))
# propagate planet inserted information # propagate planet inserted information
for key, value in source.items(): for key, value in source.items():
@ -182,6 +187,9 @@ def reconstitute(feed, entry):
links(xentry, entry) links(xentry, entry)
bozo = feed.bozo bozo = feed.bozo
if not entry.has_key('title'):
xentry.appendChild(xdoc.createElement('title'))
content(xentry, 'title', entry.get('title_detail',None), bozo) content(xentry, 'title', entry.get('title_detail',None), bozo)
content(xentry, 'summary', entry.get('summary_detail',None), bozo) content(xentry, 'summary', entry.get('summary_detail',None), bozo)
content(xentry, 'content', entry.get('content',[None])[0], bozo) content(xentry, 'content', entry.get('content',[None])[0], bozo)

View File

@ -0,0 +1,13 @@
<!--
Description: link relationship
Expect: links[0].href == 'http://example.com/1'
-->
<rss version="2.0">
<channel>
<item>
<guid>http://example.com/1</guid>
</item>
</channel>
</rss>