From 4dd8c2bca2bc6400403f130cfae239afdc0ba17a Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Tue, 5 Sep 2006 21:57:56 -0400 Subject: [PATCH] Better conversion of RSS feeds to Atom --- planet/reconstitute.py | 18 +++++++++++++----- tests/data/reconstitute/onlyguid.xml | 13 +++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 tests/data/reconstitute/onlyguid.xml diff --git a/planet/reconstitute.py b/planet/reconstitute.py index 9ec908d..361a6b4 100644 --- a/planet/reconstitute.py +++ b/planet/reconstitute.py @@ -87,14 +87,19 @@ def id(xentry, entry): def links(xentry, 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 for link in entry.links: if not 'href' in link.keys(): continue xlink = xdoc.createElement('link') - xlink.setAttribute('type', link.get('type',None)) - xlink.setAttribute('href', link.href) - xlink.setAttribute('rel', link.get('rel',None)) + xlink.setAttribute('href', link.get('href')) + if link.has_key('type'): + xlink.setAttribute('type', link.get('type')) + if link.has_key('rel'): + xlink.setAttribute('rel', link.get('rel',None)) xentry.appendChild(xlink) 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, '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 for key, value in source.items(): @@ -182,6 +187,9 @@ def reconstitute(feed, entry): links(xentry, entry) 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, 'summary', entry.get('summary_detail',None), bozo) content(xentry, 'content', entry.get('content',[None])[0], bozo) diff --git a/tests/data/reconstitute/onlyguid.xml b/tests/data/reconstitute/onlyguid.xml new file mode 100644 index 0000000..ff5d686 --- /dev/null +++ b/tests/data/reconstitute/onlyguid.xml @@ -0,0 +1,13 @@ + + + + + + http://example.com/1 + + + +