home
·
contact
·
privacy
projects
/
plomlombot-irc.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Handle too-many-URLs-in-message.
[plomlombot-irc.git]
/
plomlombot.py
diff --git
a/plomlombot.py
b/plomlombot.py
index aa7061cac656f3f6b5f768e40787ccb6fbc475c4..4d2f72dc33249e8a6744c8ca3568d52d6d997ad2 100755
(executable)
--- a/
plomlombot.py
+++ b/
plomlombot.py
@@
-339,7
+339,7
@@
def handle_url(url, notice, show_url=False):
return True
try:
return True
try:
- r = requests.get(url, timeout=5, stream=True)
+ r = requests.get(url, timeout=
1
5, stream=True)
r.raw.decode_content = True
text = r.raw.read(10000000+1)
if len(text) > 10000000:
r.raw.decode_content = True
text = r.raw.read(10000000+1)
if len(text) > 10000000:
@@
-347,13
+347,14
@@
def handle_url(url, notice, show_url=False):
except (requests.exceptions.TooManyRedirects,
requests.exceptions.ConnectionError,
requests.exceptions.InvalidURL,
except (requests.exceptions.TooManyRedirects,
requests.exceptions.ConnectionError,
requests.exceptions.InvalidURL,
+ requests.exceptions.ReadTimeout,
UnicodeError,
ValueError,
requests.exceptions.InvalidSchema) as error:
notice("TROUBLE FOLLOWING URL: " + str(error))
UnicodeError,
ValueError,
requests.exceptions.InvalidSchema) as error:
notice("TROUBLE FOLLOWING URL: " + str(error))
- return
+ return
False
if mobile_twitter_hack(url):
if mobile_twitter_hack(url):
- return
+ return
True
title = bs4.BeautifulSoup(text, "html5lib").title
if title and title.string:
prefix = "PAGE TITLE: "
title = bs4.BeautifulSoup(text, "html5lib").title
if title and title.string:
prefix = "PAGE TITLE: "
@@
-362,6
+363,7
@@
def handle_url(url, notice, show_url=False):
notice(prefix + title.string.strip())
else:
notice("PAGE HAS NO TITLE TAG")
notice(prefix + title.string.strip())
else:
notice("PAGE HAS NO TITLE TAG")
+ return True
class Session:
class Session:
@@
-416,8
+418,14
@@
class Session:
target = line.receiver
msg = str.join(" ", line.tokens[3:])[1:]
matches = re.findall("(https?://[^\s>]+)", msg)
target = line.receiver
msg = str.join(" ", line.tokens[3:])[1:]
matches = re.findall("(https?://[^\s>]+)", msg)
+ url_count = 0
for i in range(len(matches)):
for i in range(len(matches)):
- handle_url(matches[i], notice)
+ if handle_url(matches[i], notice):
+ url_count += 1
+ if url_count == 3:
+ notice("MAXIMUM NUMBER OF URLs TO PARSE PER MESSAGE "
+ "REACHED")
+ break
if "!" == msg[0]:
tokens = msg[1:].split()
argument = str.join(" ", tokens[1:])
if "!" == msg[0]:
tokens = msg[1:].split()
argument = str.join(" ", tokens[1:])