Changed code to unescape titles properly

This commit is contained in:
lukeroge 2012-02-29 21:43:11 +13:00
parent ed50bc746c
commit b169eb3fdf

View file

@ -8,24 +8,6 @@ ignored_urls = ["http://google.com", "http://youtube.com",
"http://pastebin.com", "http://mibpaste.com",
"http://fpaste.com", "http://git.io"]
wordDic = {
'"': '"',
''': '\'',
'&': '&',
'&#60;': '<',
'&#62;': '>',
'&#171;': '«',
'&quot;': '"',
'&apos;': '\'',
'&amp;': '&',
'&lt;': '<',
'&gt;': '>',
'&laquo;': '«',
'&#33;': '!',
'&#036;': '$',
' ': ' '}
def parse(match):
url = urlnorm.normalize(match.encode('utf-8'))
if url not in ignored_urls:
@ -36,15 +18,6 @@ def parse(match):
except:
return "fail"
def multiwordReplace(text, wordDic):
rc = re.compile('|'.join(map(re.escape, wordDic)))
def translate(match):
return wordDic[match.group(0)]
return rc.sub(translate, text)
@hook.regex(r'([a-zA-Z]://|www\.)?[^ ]+(\.[a-z]+)+')
def urlparser(match, say=None):
url = urlnorm.normalize(match.group().encode('utf-8'))
@ -57,7 +30,7 @@ def urlparser(match, say=None):
title = parse(url)
if title == "fail":
return
title = multiwordReplace(title, wordDic)
title = http.unescape(title)
realurl = http.get_url(url)
if realurl == url:
say("(Link) %s" % title)