1
0
mirror of http://aero2k.de/t/repos/urlbot-native.git synced 2017-09-06 15:25:38 +02:00

rename r->url; add obj['sim']

This commit is contained in:
urlbot
2014-10-06 00:19:47 +02:00
parent 6a916c701a
commit 663e2131ed

View File

@@ -129,22 +129,18 @@ def extract_url(data):
ret = None ret = None
result = re.findall("(https?://[^\s>]+)", data) result = re.findall("(https?://[^\s>]+)", data)
if result: if result:
for r in result: for url in result:
ratelimit_touch() ratelimit_touch()
if ratelimit_exceeded(): if ratelimit_exceeded():
return False return False
(status, title) = extract_title(r) (status, title) = extract_title(url)
if 0 == status: if 0 == status:
title = title.strip() title = title.strip()
lev_url = re.sub(r'https?://[^/]*/', '', r) lev_url = re.sub(r'https?://[^/]*/', '', url)
lev_res = levenshtein(lev_url, title) lev_res = levenshtein(lev_url, title)
obj = conf_load()
obj['lev'].append((lev_res, title, lev_url))
conf_save(obj)
lev_str = 'lev=%d/%d:%d ' %(lev_res, len(title), len(lev_url)) lev_str = 'lev=%d/%d:%d ' %(lev_res, len(title), len(lev_url))
sim = str_sim(title, lev_url) sim = str_sim(title, lev_url)
@@ -154,23 +150,28 @@ def extract_url(data):
sim_str = 'sim=%d/%d:%d ' %(sim_sum, sim_len_title, sim_len_url) sim_str = 'sim=%d/%d:%d ' %(sim_sum, sim_len_title, sim_len_url)
message = lev_str + sim_str + 'Title: %s: %s' %(title, r) obj = conf_load()
obj['lev'].append((lev_res, title, url))
obj['sim'].append((sim_sum, sim_len_title, sim_len_url, title, url))
conf_save(obj)
message = lev_str + sim_str + 'Title: %s: %s' %(title, url)
elif 1 == status: elif 1 == status:
if conf('image_preview'): if conf('image_preview'):
# of course it's fake, but it looks interesting at least # of course it's fake, but it looks interesting at least
char = """,._-+=\|/*`~"'""" char = """,._-+=\|/*`~"'"""
message = 'No text but %s, 1-bit ASCII art preview: [%c] %s' %( message = 'No text but %s, 1-bit ASCII art preview: [%c] %s' %(
title, random.choice(char), r title, random.choice(char), url
) )
else: else:
logger('info', 'no message sent for non-text %s (%s)' %(r, title)) logger('info', 'no message sent for non-text %s (%s)' %(url, title))
continue continue
elif 2 == status: elif 2 == status:
message = 'No title: %s' % r message = 'No title: %s' % url
elif 3 == status: elif 3 == status:
message = title message = title
else: else:
message = 'some error occurred when fetching %s' % r message = 'some error occurred when fetching %s' % url
message = message.replace('\n', '\\n') message = message.replace('\n', '\\n')