Skip to content

Commit

Permalink
Merge pull request sopel-irc#1045 from dgw/deprecate-wa
Browse files Browse the repository at this point in the history
[calc] Remove .wa, as API now requires a key

Replacement is on PyPI as `sopel-modules.wolfram`
  • Loading branch information
maxpowa committed Apr 4, 2016
2 parents 8b9da72 + 4c817b0 commit 6f3558d
Showing 1 changed file with 0 additions and 41 deletions.
41 changes: 0 additions & 41 deletions sopel/modules/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,47 +65,6 @@ def py(bot, trigger):
bot.reply('Sorry, no result.')


@commands('wa', 'wolfram')
@example('.wa sun mass / earth mass',
'[WOLFRAM] M_sun\/M_earth (solar mass per Earth mass) = 332948.6')
def wa(bot, trigger):
"""Wolfram Alpha calculator"""
if not trigger.group(2):
return bot.reply("No search term.")
query = trigger.group(2)
uri = BASE_TUMBOLIA_URI + 'wa/'
try:
answer = web.get(uri + web.quote(query.replace('+', 'plus')), 45,
dont_decode=True)
except timeout:
return bot.say('[WOLFRAM ERROR] Request timed out')
if answer:
answer = answer.decode('unicode_escape')
answer = HTMLParser.HTMLParser().unescape(answer)
# This might not work if there are more than one instance of escaped
# unicode chars But so far I haven't seen any examples of such output
# examples from Wolfram Alpha
match = re.search('\\\:([0-9A-Fa-f]{4})', answer)
if match is not None:
char_code = match.group(1)
char = unichr(int(char_code, 16))
answer = answer.replace('\:' + char_code, char)
waOutputArray = answer.split(";")
if(len(waOutputArray) < 2):
if(answer.strip() == "Couldn't grab results from json stringified precioussss."):
# Answer isn't given in an IRC-able format, just link to it.
bot.say('[WOLFRAM]Couldn\'t display answer, try http://www.wolframalpha.com/input/?i=' + query.replace(' ', '+'))
else:
bot.say('[WOLFRAM ERROR]' + answer)
else:

bot.say('[WOLFRAM] ' + waOutputArray[0] + " = "
+ waOutputArray[1])
waOutputArray = []
else:
bot.reply('Sorry, no result.')


if __name__ == "__main__":
from sopel.test_tools import run_example_tests
run_example_tests(__file__)

0 comments on commit 6f3558d

Please sign in to comment.