diff options
author | Sean B. Palmer <sbp@aldebaran.local> | 2010-11-06 12:52:35 +0000 |
---|---|---|
committer | Sean B. Palmer <sbp@aldebaran.local> | 2010-11-06 12:52:35 +0000 |
commit | 9ae58d0a353fc610e9affc1216b2cdc77e8cf89c (patch) | |
tree | 1026c6ed477af70783ae6b11520016b044f816c1 /modules | |
parent | 63b981c994f2b41a9fcee003b7418f3cb10ba6a4 (diff) | |
download | bot-9ae58d0a353fc610e9affc1216b2cdc77e8cf89c.tar.gz bot-9ae58d0a353fc610e9affc1216b2cdc77e8cf89c.tar.bz2 bot-9ae58d0a353fc610e9affc1216b2cdc77e8cf89c.zip |
New calculator function, as tested by yano and jasondavies!
Diffstat (limited to 'modules')
-rwxr-xr-x | modules/calc.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/modules/calc.py b/modules/calc.py index e664cb2..c4b304d 100755 --- a/modules/calc.py +++ b/modules/calc.py @@ -43,7 +43,7 @@ def calc(phenny, input): precision = 2 query = web.urllib.quote(query.encode('utf-8')) - uri = 'http://futureboy.homeip.net/fsp/frink.fsp?fromVal=' + uri = 'http://futureboy.us/fsp/frink.fsp?fromVal=' bytes = web.get(uri + query) m = r_result.search(bytes) if m: @@ -63,8 +63,28 @@ def calc(phenny, input): 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.""" + q = input.group(2).encode('utf-8') + q = q.replace('\xcf\x86', 'phi') # utf-8 U+03C6 + 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)) + parts = bytes.split('",') + answer = [p for p in parts if p.startswith('rhs: "')][0][6:] + if answer: + answer = answer.decode('unicode-escape') + answer = answer.replace('<sup>', '^(') + answer = answer.replace('</sup>', ')') + answer = web.decode(answer) + phenny.say(answer) + else: phenny.say('Sorry, no result.') +c.commands = ['c'] +c.example = '.c 5 + 3' + if __name__ == '__main__': print __doc__.strip() |