From 14943fb8e4a52f7ef5b669bdce14e323d9a31c7b Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Thu, 18 Apr 2013 18:26:31 -0300 Subject: [PATCH] Try to fix whitespace in definitions. Because legoktm didn't think ahead blarghlefargle. --- commands/urbandictionary.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/commands/urbandictionary.py b/commands/urbandictionary.py index 4480500..beb3a40 100644 --- a/commands/urbandictionary.py +++ b/commands/urbandictionary.py @@ -4,6 +4,7 @@ # from json import loads +import re from urllib import quote from urllib2 import urlopen @@ -25,9 +26,9 @@ class UrbanDictionary(Command): query = urlopen(url.format(q)).read() res = loads(query) if res['result_type'] == 'exact': - definition = res['list'][0]['definition'].replace("\n", " ") - example = res['list'][0]['example'].replace("\n", " ") - msg = 'Definition: {0}; example: {1}'.format(definition, example) + definition = re.sub(r"\s+", " ", res['list'][0]['definition']) + example = re.sub(r"\s+", " ", res['list'][0]['example']) + msg = '{0}; example: {1}'.format(definition, example) self.reply(data, msg) elif res['result_type'] == 'fulltext': L = [i['word'] for i in res['list']]