WolframAlpha: python 3 compatible.

This commit is contained in:
oddluck 2020-02-13 12:35:58 +00:00
parent 44d8d33a4d
commit bcaa273e87
8 changed files with 30 additions and 16 deletions

18
WolframAlpha/.travis.yml Normal file
View File

@ -0,0 +1,18 @@
language: python
python:
- "2.7"
- "3.4"
- "pypy"
# command to install dependencies,
install:
- pip install -vr requirements.txt||true
# command to run tests, e.g. python setup.py test
script:
- echo $TRAVIS_PYTHON_VERSION
- cd .. && supybot-test WolframAlpha
notifications:
email: false
irc: "irc.efnet.net#supybot"
webhooks: http://n.tkte.ch/h/3527/rm2ycnsYzBtH8Qqg2AAmqjTM
matrix:
fast_finish: true

View File

@ -12,6 +12,7 @@ here. This should describe *what* the plugin does.
import supybot
import supybot.world as world
import importlib
# Use this for the version of this plugin. You may wish to put a CVS keyword
# in here if you're keeping the plugin in CVS or some similar system.
@ -32,8 +33,8 @@ from . import plugin
from imp import reload
# In case we're being reloaded.
reload(config)
reload(plugin)
importlib.reload(config)
importlib.reload(plugin)
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
###
# Copyright (c) 2012-2014, spline
# All rights reserved.
@ -110,8 +109,8 @@ class WolframAlpha(callbacks.Plugin):
if document.attrib['success'] == 'false' and document.attrib['error'] == 'true':
errormsgs = []
for error in document.findall('.//error'):
errorcode = error.find('code').text.encode('utf-8')
errormsg = error.find('msg').text.encode('utf-8')
errorcode = error.find('code').text
errormsg = error.find('msg').text
errormsgs.append("{0} - {1}".format(errorcode, errormsg))
# log and report to irc if we have these.
self.log.debug("ERROR processing request for: {0} message: {1}".format(optinput, errormsgs))
@ -121,13 +120,13 @@ class WolframAlpha(callbacks.Plugin):
elif document.attrib['success'] == 'false' and document.attrib['error'] == 'false':
errormsgs = [] # list to contain whatever is there.
for error in document.findall('.//futuretopic'):
errormsg = error.attrib['msg'].encode('utf-8')
errormsg = error.attrib['msg']
errormsgs.append("FUTURE TOPIC: {0}".format(errormsg))
for error in document.findall('.//didyoumeans'):
errormsg = error.find('didyoumean').text.encode('utf-8')
errormsg = error.find('didyoumean').text
errormsgs.append("Did you mean? {0}".format(errormsg))
for error in document.findall('.//tips'):
errormsg = error.find('tip').attrib['text'].text.encode('utf-8')
errormsg = error.find('tip').attrib['text'].text
errormsgs.append("TIPS: {0}".format(errormsg))
# now output the messages to irc and log.
self.log.debug("ERROR with input: {0} API returned: {1}".format(optinput, errormsgs))
@ -140,7 +139,7 @@ class WolframAlpha(callbacks.Plugin):
outputlist = {}
# each answer has a different amount of pods.
for pod in document.findall('.//pod'):
title = pod.attrib['title'].encode('utf-8') # title of it.
title = pod.attrib['title'] # title of it.
position = int(pod.attrib['position']) # store pods int when we sort.
outputlist[position] = title # pu
for plaintext in pod.findall('.//plaintext'):
@ -221,20 +220,16 @@ class WolframAlpha(callbacks.Plugin):
# each answer has a different amount of pods.
for pod in document.findall('.//pod'):
title = pod.attrib['title'].encode('utf-8') # title of it.
title = pod.attrib['title'] # title of it.
if title == "Result":
for plaintext in pod.findall('.//plaintext'):
print(plaintext.text)
print((plaintext.text))
if 'not compatible' in plaintext.text:
irc.reply('Conversion from btc to %s not available' % currency)
else:
converted_amount = plaintext.text.split('(')[0].strip()
if '\:' in converted_amount:
converted_amount = converted_amount.replace('\:','\\u').decode("unicode_escape")
irc.reply('%s%d = %s' % ('\\u0e3f'.decode("unicode_escape"),amount, converted_amount))
irc.reply('%s%d = %s' % ('\u0e3f', amount, converted_amount))
btc = wrap(btc,['float', 'text'])