Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for creating short URLs. #10

Merged
merged 2 commits into from Feb 1, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions plugins/urls.py
Expand Up @@ -2,11 +2,11 @@
from util import hook, urlnorm, http from util import hook, urlnorm, http


ignore = ['buttbot'] ignore = ['buttbot']
is_gd = 'http://is.gd/create.php?format=simple&url=%s'


@hook.regex(r'([a-zA-Z]+://|www\.)[^ ]+') @hook.regex(r'([a-zA-Z]+://|www\.)[^ ]+')
def show_title(match, nick='', chan='', say=None): def show_title(match, nick='', chan='', say=None):
url = urlnorm.normalize(match.group().encode('utf-8')) matched = match.group().encode('utf-8')
url = urlnorm.normalize(matched)


if not url in ignore and not nick in ignore: if not url in ignore and not nick in ignore:
page, response = http.get_html_and_response(url) page, response = http.get_html_and_response(url)
Expand All @@ -30,8 +30,10 @@ def show_title(match, nick='', chan='', say=None):
message = 'URL title: %s' % (''.join(titleList)) message = 'URL title: %s' % (''.join(titleList))


if len(url) >= 80: if len(url) >= 80:
# Get the short URL. short_url = http.get(
short_url = http.get(is_gd % (url)) 'http://is.gd/create.php',
query_params = {'format': 'simple', 'url': matched}
)


# Cheap error checking # Cheap error checking
if 'error: please' not in short_url.lower(): if 'error: please' not in short_url.lower():
Expand Down