changeset 69:ae0f2f438a95

myrss: add support for new "purl" RSS type
author paulo
date Thu, 11 Jun 2015 22:03:34 -0700
parents 66a232bae83c
children 3456dd3e8660
files myrss/myrss_app.py
diffstat 1 files changed, 19 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/myrss/myrss_app.py	Thu Jun 11 21:25:03 2015 -0700
     1.2 +++ b/myrss/myrss_app.py	Thu Jun 11 22:03:34 2015 -0700
     1.3 @@ -87,6 +87,23 @@
     1.4  	return (title, link, items)
     1.5  
     1.6  
     1.7 +def _go_purl_rss(elementTree):
     1.8 +	ns = "http://purl.org/rss/1.0/"
     1.9 +
    1.10 +	title = _strip_if_not_none(elementTree.find("{%s}channel/{%s}title" % (ns, ns)).text)
    1.11 +	link = elementTree.find("{%s}channel/{%s}link" % (ns, ns)).text
    1.12 +
    1.13 +	items = []
    1.14 +
    1.15 +	for i in elementTree.findall("{%s}item" % ns)[:MAX_ITEMS]:
    1.16 +		it_title = _strip_if_not_none(i.find("{%s}title" % ns).text)
    1.17 +		it_link = i.find("{%s}link" % ns).text
    1.18 +
    1.19 +		items.append((it_title, it_link))
    1.20 +
    1.21 +	return (title, link, items)
    1.22 +
    1.23 +
    1.24  _STRIP_HTML_RE = re.compile(r"<.*?>")
    1.25  _htmlParser = HTMLParser.HTMLParser()
    1.26  
    1.27 @@ -159,6 +176,8 @@
    1.28  			raise NotImplementedError("Unsupported rss version")
    1.29  	elif parsed_root_tag == ("http://www.w3.org/2005/Atom", "feed"):
    1.30  		ret = _go_atom(elementTree)
    1.31 +	elif parsed_root_tag == ("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "RDF"):
    1.32 +		ret = _go_purl_rss(elementTree)
    1.33  	else:
    1.34  		raise NotImplementedError("Unknown root tag")
    1.35