Commit 7f1849bd authored by Romain Courteaud's avatar Romain Courteaud

Split download/parsing of RSS data in 2 functions.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27777 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 997485c9
from urllib2 import HTTPPasswordMgrWithDefaultRealm, HTTPBasicAuthHandler, \ from urllib2 import HTTPPasswordMgrWithDefaultRealm, HTTPBasicAuthHandler, \
build_opener, install_opener, urlopen, HTTPError build_opener, install_opener, urlopen, HTTPError
from xml.dom.minidom import parse from xml.dom.minidom import parseString
import md5 import md5
from HTMLParser import HTMLParser from HTMLParser import HTMLParser
...@@ -24,8 +24,11 @@ def getRssDataAsDict(url, username, password): ...@@ -24,8 +24,11 @@ def getRssDataAsDict(url, username, password):
return {'title': 'Page not found.' } return {'title': 'Page not found.' }
except : except :
return {'title': 'Fetching Rss failed.' } return {'title': 'Fetching Rss failed.' }
return parseRssDataAsDict(file.read())
def parseRssDataAsDict(rss_string):
try: try:
xmlDoc = parse(file).documentElement xmlDoc = parseString(rss_string).documentElement
except : except :
return {'title': 'Parsing RSS failed.' } return {'title': 'Parsing RSS failed.' }
if(xmlDoc.tagName.startswith('rss') or xmlDoc.tagName.startswith('rdf') ): if(xmlDoc.tagName.startswith('rss') or xmlDoc.tagName.startswith('rdf') ):
......
395 402
\ No newline at end of file \ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment