Skip to content

Commit

Permalink
Calculator updates, and .py and .wa implementations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean B. Palmer committed Nov 6, 2010
1 parent 9ae58d0 commit ca95157
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
21 changes: 20 additions & 1 deletion modules/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ def calc(phenny, input):
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))
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(u'\xc2\xa0', ',')
answer = answer.replace('<sup>', '^(')
answer = answer.replace('</sup>', ')')
answer = web.decode(answer)
Expand All @@ -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()
4 changes: 0 additions & 4 deletions modules/oblique.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ def o(phenny, input):
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" + \
Expand Down

0 comments on commit ca95157

Please sign in to comment.