From ca95157acbe6e340573130e45a851b39e547159d Mon Sep 17 00:00:00 2001 From: "Sean B. Palmer" Date: Sat, 6 Nov 2010 13:58:51 +0000 Subject: [PATCH] Calculator updates, and .py and .wa implementations. --- modules/calc.py | 21 ++++++++++++++++++++- modules/oblique.py | 4 ---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/modules/calc.py b/modules/calc.py index c4b304d..ab0f3fa 100755 --- a/modules/calc.py +++ b/modules/calc.py @@ -70,7 +70,7 @@ calc.example = '.calc 5 + 3' def c(phenny, input): """Google calculator.""" q = input.group(2).encode('utf-8') - q = q.replace('\xcf\x86', 'phi') # utf-8 U+03C6 + q = q.replace('\xcf\x95', 'phi') # utf-8 U+03D5 q = q.replace('\xcf\x80', 'pi') # utf-8 U+03C0 uri = 'http://www.google.com/ig/calculator?q=' bytes = web.get(uri + web.urllib.quote(q)) @@ -78,6 +78,7 @@ def c(phenny, input): answer = [p for p in parts if p.startswith('rhs: "')][0][6:] if answer: answer = answer.decode('unicode-escape') + answer = answer.replace(u'\xc2\xa0', ',') answer = answer.replace('', '^(') answer = answer.replace('', ')') answer = web.decode(answer) @@ -86,5 +87,23 @@ def c(phenny, input): c.commands = ['c'] c.example = '.c 5 + 3' +def py(phenny, input): + query = input.group(2) + uri = 'http://tumbolia.appspot.com/py/' + answer = web.get(uri + web.urllib.quote(query)) + if answer: + phenny.say(answer) + else: phenny.reply('Sorry, no result.') +py.commands = ['py'] + +def wa(phenny, input): + query = input.group(2) + uri = 'http://tumbolia.appspot.com/wa/' + answer = web.get(uri + web.urllib.quote(query)) + if answer: + phenny.say(answer) + else: phenny.reply('Sorry, no result.') +wa.commands = ['wa'] + if __name__ == '__main__': print __doc__.strip() diff --git a/modules/oblique.py b/modules/oblique.py index b19cb50..be1ca9d 100755 --- a/modules/oblique.py +++ b/modules/oblique.py @@ -87,10 +87,6 @@ o.commands = ['o'] o.example = '.o servicename arg1 arg2 arg3' o.services = {} -def py(phenny, input): - service(phenny, input, 'py', input.group(2)) -py.commands = ['py'] - def snippet(phenny, input): py = "BeautifulSoup.BeautifulSoup(re.sub('<.*?>|(?<= ) +', '', " + \ "eval(urllib.urlopen('http://ajax.googleapis.com/ajax/serv" + \