Commit 8d043e5e authored by Mindiell's avatar Mindiell

Added easy exceptions for url title getter

parent 807dfe12
......@@ -61,8 +61,15 @@ def get_url(message):
def get_title(message):
title = ""
website = ""
exceptions = [
"twitter.com",
"github.com",
]
try:
url = get_url(message)#re.search("(http[^ ]*)", msg).group(1)
url = get_url(message)
for exception in exceptions:
if exception in url:
return ("", "")
website = re.search("//([^/]*)", url).group(1)
f = urllib.URLopener().open(url)
content = f.read()
......@@ -76,6 +83,8 @@ def get_title(message):
title = re.sub(""|"", '"', title)
title = re.sub("'|'", "'", title)
title = re.sub("&|&", "&", title)
# Multiple lines titles are compressed
title = re.sub("\n|\r", "", title)
return (title, website)
def is_moderator(name):
......@@ -165,7 +174,7 @@ class Wantzel(object):
print("Message received: %s %s %s" % (user, channel, msg))
# Whatever is done, get the title of an existing url in a message
title = ""
if "http" in msg and "twitter.com" not in msg:
if "http" in msg:
title, website = get_title(msg)
# Never answer to botself
if user!=config.nickname:
......
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