2008-02-23 07:17:06 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# coding=utf-8
|
|
|
|
"""
|
|
|
|
calc.py - Phenny Calculator Module
|
|
|
|
Copyright 2008, Sean B. Palmer, inamidst.com
|
|
|
|
Licensed under the Eiffel Forum License 2.
|
|
|
|
|
|
|
|
http://inamidst.com/phenny/
|
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
|
|
|
import web
|
2019-06-20 21:45:18 -04:00
|
|
|
from modules.search import newton_api
|
2008-02-23 07:17:06 -05:00
|
|
|
|
2019-06-20 21:45:18 -04:00
|
|
|
operations = {'simplify', 'factor', 'derive', 'integrate', 'zeroes', 'tangent',
|
|
|
|
'area', 'cos', 'sin', 'tan', 'arccos', 'arcsin', 'arctan', 'abs', 'log'}
|
2013-10-01 02:33:47 -04:00
|
|
|
|
|
|
|
def c(phenny, input):
|
2019-06-20 21:45:18 -04:00
|
|
|
"""Newton calculator."""
|
2012-01-03 14:09:34 -05:00
|
|
|
if not input.group(2):
|
|
|
|
return phenny.reply("Nothing to calculate.")
|
|
|
|
q = input.group(2)
|
2019-06-20 21:45:18 -04:00
|
|
|
q = q.split(' ', 1)
|
|
|
|
|
|
|
|
if len(q) > 1 and q[0] in operations:
|
|
|
|
operation = q[0]
|
|
|
|
expression = q[1]
|
|
|
|
elif len(q) > 0:
|
|
|
|
operation = 'simplify'
|
|
|
|
expression = q[0]
|
|
|
|
|
|
|
|
result = newton_api(operation, expression)
|
2013-11-05 12:19:02 -05:00
|
|
|
|
2019-06-20 21:45:18 -04:00
|
|
|
if result:
|
|
|
|
phenny.say(result)
|
2013-10-01 02:33:47 -04:00
|
|
|
else:
|
2017-05-28 00:42:44 -04:00
|
|
|
phenny.reply("Sorry, no result.")
|
2010-11-06 08:52:35 -04:00
|
|
|
c.commands = ['c']
|
|
|
|
c.example = '.c 5 + 3'
|
2019-06-20 21:45:18 -04:00
|
|
|
c.example = '.c integrate 1/3 x^3 + x^2 + C'
|
2010-11-06 08:52:35 -04:00
|
|
|
|
2013-10-01 02:33:47 -04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2012-01-03 14:09:34 -05:00
|
|
|
print(__doc__.strip())
|