calc: remove deprecated, fix wa output, add test
This commit is contained in:
@@ -27,46 +27,6 @@ subs = [
|
||||
('mbps', '(megabits / second)')
|
||||
]
|
||||
|
||||
def calc(phenny, input):
|
||||
"""Use the Frink online calculator."""
|
||||
q = input.group(2)
|
||||
if not q:
|
||||
return phenny.say('0?')
|
||||
|
||||
query = q[:]
|
||||
for a, b in subs:
|
||||
query = re.sub(a, b, query)
|
||||
query = query.rstrip(' \t')
|
||||
|
||||
precision = 5
|
||||
if query[-3:] in ('GBP', 'USD', 'EUR', 'NOK'):
|
||||
precision = 2
|
||||
query = web.quote(query)
|
||||
|
||||
uri = 'http://futureboy.us/fsp/frink.fsp?fromVal='
|
||||
bytes = web.get(uri + query)
|
||||
m = r_result.search(bytes)
|
||||
if m:
|
||||
result = m.group(1)
|
||||
result = r_tag.sub('', result) # strip span.warning tags
|
||||
result = result.replace('>', '>')
|
||||
result = result.replace('(undefined symbol)', '(?) ')
|
||||
|
||||
if '.' in result:
|
||||
try: result = str(round(float(result), precision))
|
||||
except ValueError: pass
|
||||
|
||||
if not result.strip():
|
||||
result = '?'
|
||||
elif ' in ' in q:
|
||||
result += ' ' + q.split(' in ', 1)[1]
|
||||
|
||||
phenny.say(q + ' = ' + result[:350])
|
||||
else: phenny.reply("Sorry, can't calculate that.")
|
||||
phenny.say('Note that .calc is deprecated, consider using .c')
|
||||
calc.commands = ['calc']
|
||||
calc.example = '.calc 5 + 3'
|
||||
|
||||
def c(phenny, input):
|
||||
"""Google calculator."""
|
||||
if not input.group(2):
|
||||
@@ -105,6 +65,7 @@ def wa(phenny, input):
|
||||
query = input.group(2)
|
||||
uri = 'http://tumbolia.appspot.com/wa/'
|
||||
answer = web.get(uri + web.quote(query.replace('+', '%2B')))
|
||||
answer = answer.split(';')[1]
|
||||
if answer:
|
||||
phenny.say(answer)
|
||||
else: phenny.reply('Sorry, no result.')
|
||||
|
||||
Reference in New Issue
Block a user