comparison website/issues/detectors/rsswriter.py @ 6465:bed1313898d4

Force time format to include offset, use dc:creator not author publish times were missing timezone even though %z was in the format string. Since time is GMT, hardcoded +0000. Author element is required to be a real address. Use dublin core creator instead (dc;creator). Had to add namespace xmlns:dc to root element.
author John Rouillard <rouilj@ieee.org>
date Fri, 06 Aug 2021 01:20:45 -0400
parents 0014af559224
children
comparison
equal deleted inserted replaced
6464:28461636e249 6465:bed1313898d4
61 # SOFTWARE. 61 # SOFTWARE.
62 # 62 #
63 63
64 64
65 # The strftime format to use for <pubDate>s. 65 # The strftime format to use for <pubDate>s.
66 RSS20_DATE_FORMAT = '%a, %d %b %Y %H:%M:%S %z' 66 RSS20_DATE_FORMAT = '%a, %d %b %Y %H:%M:%S +0000'
67 67
68 68
69 def newRss(title, link, description): 69 def newRss(title, link, description):
70 """Returns an XML Document containing an RSS 2.0 feed with no items.""" 70 """Returns an XML Document containing an RSS 2.0 feed with no items."""
71 import xml.dom.minidom 71 import xml.dom.minidom
72 rss = xml.dom.minidom.Document() 72 rss = xml.dom.minidom.Document()
73 73
74 root = rss.appendChild(rss.createElement("rss")) 74 root = rss.appendChild(rss.createElement("rss"))
75 root.setAttribute("version", "2.0") 75 root.setAttribute("version", "2.0")
76 root.setAttribute("xmlns:atom","http://www.w3.org/2005/Atom") 76 root.setAttribute("xmlns:atom","http://www.w3.org/2005/Atom")
77 root.setAttribute("xmlns:dc","http://purl.org/dc/elements/1.1/")
77 78
78 channel = root.appendChild(rss.createElement("channel")) 79 channel = root.appendChild(rss.createElement("channel"))
79 addEl = lambda tag,value: channel.appendChild(rss.createElement(tag)).appendChild(rss.createTextNode(value)) 80 addEl = lambda tag,value: channel.appendChild(rss.createElement(tag)).appendChild(rss.createTextNode(value))
80 def addElA(tag,attr): 81 def addElA(tag,attr):
81 node=rss.createElement(tag) 82 node=rss.createElement(tag)
173 addEl(item, 'link', issuelink) 174 addEl(item, 'link', issuelink)
174 addEl(item, 'guid', issuelink + '#' + date.replace(' ','+')) 175 addEl(item, 'guid', issuelink + '#' + date.replace(' ','+'))
175 addEl(item, 'comments', issuelink) 176 addEl(item, 'comments', issuelink)
176 addEl(item, 'description', desc.replace('&','&amp;').replace('<','&lt;').replace('\n', '<br>\n')) 177 addEl(item, 'description', desc.replace('&','&amp;').replace('<','&lt;').replace('\n', '<br>\n'))
177 addEl(item, 'pubDate', date) 178 addEl(item, 'pubDate', date)
178 addEl(item, 'author', 179 # use dc:creator as username is not valid email address and
180 # author element must be valid email address
181 # addEl(item, 'author',
182 addEl(item, 'dc:creator',
179 '%s' % ( 183 '%s' % (
180 db.user.get(userid, 'username') 184 db.user.get(userid, 'username')
181 ) 185 )
182 ) 186 )
183 187

Roundup Issue Tracker: http://roundup-tracker.org/