Google: Stop output when there are no result.

This commit is contained in:
Terje Hoås 2012-08-17 17:16:26 +02:00
parent b5e965c48a
commit e1adc011c3

View File

@ -269,7 +269,7 @@ class Google(callbacks.PluginRegexp):
"""
urlig = self._googleUrlIG(expr)
js = utils.web.getUrl(urlig).decode('utf8')
# fix bad google json
# Convert JavaScript to JSON. Ouch.
js = js \
.replace('lhs:','"lhs":') \
.replace('rhs:','"rhs":') \
@ -278,11 +278,6 @@ class Google(callbacks.PluginRegexp):
.replace('\\', '\\\\')
js = json.loads(js)
# Currency conversion
if js['icc'] == True:
irc.reply("%s = %s" % (js['lhs'], js['rhs'],))
return
url = self._googleUrl(expr)
html = utils.web.getUrl(url).decode('utf8')
match = self._calcRe1.search(html)
@ -294,8 +289,13 @@ class Google(callbacks.PluginRegexp):
s = self._calcFontRe.sub(r',', s)
s = self._calcTimesRe.sub(r'*', s)
s = utils.web.htmlToText(s)
if ' = ' in s: # Extra check, since the regex seems to fail.
irc.reply(s)
else:
return
elif js['lhs'] and js['rhs']:
# Outputs the original result. Might look ugly.
irc.reply("%s = %s" % (js['lhs'], js['rhs'],))
return
irc.reply(_('Google says: Error: %s.') % (js['error'],))
irc.reply('Google\'s calculator didn\'t come up with anything.')
calc = wrap(calc, ['text'])