parent
47b8c12fbb
commit
e70399b654
11
morss.py
11
morss.py
|
@ -60,6 +60,9 @@ if 'REQUEST_URI' in os.environ:
|
||||||
import cgitb
|
import cgitb
|
||||||
cgitb.enable()
|
cgitb.enable()
|
||||||
|
|
||||||
|
class MorssException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
def log(txt):
|
def log(txt):
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
if HOLD:
|
if HOLD:
|
||||||
|
@ -475,7 +478,7 @@ def Gather(url, cachePath, options):
|
||||||
log(url)
|
log(url)
|
||||||
|
|
||||||
if url is None:
|
if url is None:
|
||||||
return False
|
raise MorssException('No url provided')
|
||||||
|
|
||||||
if urlparse.urlparse(url).scheme not in PROTOCOL:
|
if urlparse.urlparse(url).scheme not in PROTOCOL:
|
||||||
url = 'http://' + url
|
url = 'http://' + url
|
||||||
|
@ -510,7 +513,7 @@ def Gather(url, cachePath, options):
|
||||||
con = urllib2.build_opener(opener).open(url, timeout=TIMEOUT)
|
con = urllib2.build_opener(opener).open(url, timeout=TIMEOUT)
|
||||||
xml = con.read()
|
xml = con.read()
|
||||||
except (IOError, httplib.HTTPException):
|
except (IOError, httplib.HTTPException):
|
||||||
return False
|
raise MorssException('Error downloading feed')
|
||||||
|
|
||||||
cache.set('xml', xml)
|
cache.set('xml', xml)
|
||||||
cache.set('etag', con.headers.getheader('etag'))
|
cache.set('etag', con.headers.getheader('etag'))
|
||||||
|
@ -543,10 +546,10 @@ def Gather(url, cachePath, options):
|
||||||
return Gather(link, cachePath, options)
|
return Gather(link, cachePath, options)
|
||||||
else:
|
else:
|
||||||
log('no-link html')
|
log('no-link html')
|
||||||
return False
|
raise MorssException('Link provided is an HTML page, which doesn\'t link to a feed')
|
||||||
else:
|
else:
|
||||||
log('random page')
|
log('random page')
|
||||||
return False
|
raise MorssException('Link provided is not a valid feed')
|
||||||
|
|
||||||
size = len(rss.items)
|
size = len(rss.items)
|
||||||
startTime = time.time()
|
startTime = time.time()
|
||||||
|
|
Loading…
Reference in New Issue