Merge pull request #388 from Hoaas/testing

Google: Stop output when there are no result.
This commit is contained in:
Valentin Lorentz 2012-08-17 08:27:46 -07:00
commit 0780d445e2
1 changed files with 10 additions and 10 deletions

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,10 +289,15 @@ class Google(callbacks.PluginRegexp):
s = self._calcFontRe.sub(r',', s)
s = self._calcTimesRe.sub(r'*', s)
s = utils.web.htmlToText(s)
irc.reply(s)
else:
irc.reply(_('Google says: Error: %s.') % (js['error'],))
irc.reply('Google\'s calculator didn\'t come up with anything.')
if ' = ' in s: # Extra check, since the regex seems to fail.
irc.reply(s)
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'])
_phoneRe = re.compile(r'Phonebook.*?<font size=-1>(.*?)<a href')