def slack_message(): results = find_and_calc(request.args.get("text", request.form.get("text", ""))) if results: response = {"text": "\n".join("`%s = %s`" % (formula, result) for formula, result in results)} else: response = {"msg": "No formulas found."} return json.dumps(response)
def lambda_handler(params, context): results = find_and_calc(params['text']) logging.info('Found %d formulas in text "%s" --> %s', len(results or []), params['text'], results) if results: return { 'text': '\n'.join('`%s = %s`' % (formula, result) for formula, result in results) } return None
def slack_message(): results = find_and_calc( request.args.get('text', request.form.get('text', ''))) if results: response = { 'text': '\n'.join('`%s = %s`' % (formula, result) for formula, result in results) } else: response = {'msg': 'No formulas found.'} return json.dumps(response)
def lambda_handler(params, context): results = find_and_calc(params['text']) logging.info( 'Found %d formulas in text "%s" --> %s', len(results or []), params['text'], results) if results: return { 'text': '\n'.join( '`%s = %s`' % (formula, result) for formula, result in results ) } return None
#!/usr/bin/env python """For quick testing on cmdline, you can run this file with arguments to be parsed as text for formulas, like: python cmdline.py 'What is 1 + 2?' """ from sys import argv from calc import find_and_calc if __name__ == '__main__': for arg in argv[1:]: print '==] %s' % arg for index, (formula, result) in enumerate(find_and_calc(arg) or []): print ' #%d %s --> %s' % (index + 1, formula, result)