mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 19:22:45 +01:00
RSS: Add Python 3 support.
This commit is contained in:
parent
6266d0f16f
commit
ad25f17639
@ -262,7 +262,7 @@ class RSS(callbacks.Plugin):
|
|||||||
try:
|
try:
|
||||||
self.log.debug('Downloading new feed from %u', url)
|
self.log.debug('Downloading new feed from %u', url)
|
||||||
results = feedparser.parse(url)
|
results = feedparser.parse(url)
|
||||||
if 'bozo_exception' in results:
|
if 'bozo_exception' in results and not results['entries']:
|
||||||
raise results['bozo_exception']
|
raise results['bozo_exception']
|
||||||
except feedparser.sgmllib.SGMLParseError:
|
except feedparser.sgmllib.SGMLParseError:
|
||||||
self.log.exception('Uncaught exception from feedparser:')
|
self.log.exception('Uncaught exception from feedparser:')
|
||||||
|
@ -189,8 +189,15 @@ class HtmlToText(HTMLParser, object):
|
|||||||
def htmlToText(s, tagReplace=' '):
|
def htmlToText(s, tagReplace=' '):
|
||||||
"""Turns HTML into text. tagReplace is a string to replace HTML tags with.
|
"""Turns HTML into text. tagReplace is a string to replace HTML tags with.
|
||||||
"""
|
"""
|
||||||
if sys.version_info[0] >= 3 and isinstance(s, bytes):
|
try:
|
||||||
s = s.decode()
|
import chardet
|
||||||
|
except ImportError:
|
||||||
|
s = s.decode('utf8')
|
||||||
|
else:
|
||||||
|
u = chardet.universaldetector.UniversalDetector()
|
||||||
|
u.feed(s)
|
||||||
|
u.close()
|
||||||
|
s = s.decode(u.result['encoding'])
|
||||||
x = HtmlToText(tagReplace)
|
x = HtmlToText(tagReplace)
|
||||||
x.feed(s)
|
x.feed(s)
|
||||||
return x.getText()
|
return x.getText()
|
||||||
|
Loading…
Reference in New Issue
Block a user