[framalink] some refactor

This commit is contained in:
nemunaire 2015-10-12 06:52:44 +02:00
parent 2cd8f70cdc
commit aa4050f6cd

View File

@ -34,6 +34,7 @@ PROVIDERS = {
} }
DEFAULT_PROVIDER = "framalink" DEFAULT_PROVIDER = "framalink"
PROVIDERS_NETLOC = [urlparse(url, "http").netloc for f, url in PROVIDERS.values()]
# LOADING ############################################################# # LOADING #############################################################
@ -81,15 +82,16 @@ def parseresponse(msg):
try: try:
urls = re.findall("([a-zA-Z0-9+.-]+:(?://)?[^ :]+)", msg.text) urls = re.findall("([a-zA-Z0-9+.-]+:(?://)?[^ :]+)", msg.text)
for url in urls: for url in urls:
o = urlparse(url) o = urlparse(url, "http")
if o.scheme != "":
if o.netloc == "ycc.fr" or o.netloc == "tinyurl.com" or o.netloc == "frama.link" or ( # Skip short URLs
o.netloc == "" and len(o.path) < 10): if o.netloc == "" or o.netloc in PROVIDERS or len(o.netloc) + len(o.path) < 17:
continue continue
for recv in msg.receivers:
if recv not in LAST_URLS: for recv in msg.receivers:
LAST_URLS[recv] = list() if recv not in LAST_URLS:
LAST_URLS[recv].append(url) LAST_URLS[recv] = list()
LAST_URLS[recv].append(url)
except: except:
pass pass
return msg return msg
@ -119,12 +121,9 @@ def cmd_reduceurl(msg):
res = list() res = list()
for url in minify: for url in minify:
o = urlparse(url, "http") o = urlparse(url, "http")
if o.scheme != "": minief_url = reduce(url)
minief_url = reduce(url) if o.netloc == "":
if o.netloc == "": res.append(gen_response(minief_url, msg, o.scheme))
res.append(gen_response(minief_url, msg, o.scheme))
else:
res.append(gen_response(minief_url, msg, o.netloc))
else: else:
res.append(gen_response(None, msg, url)) res.append(gen_response(minief_url, msg, o.netloc))
return res return res