Port to python3, fix ssl support
This commit is contained in:
@@ -17,8 +17,8 @@ r_tag = re.compile(r'<\S+.*?>')
|
||||
subs = [
|
||||
(' in ', ' -> '),
|
||||
(' over ', ' / '),
|
||||
(u'£', 'GBP '),
|
||||
(u'€', 'EUR '),
|
||||
('£', 'GBP '),
|
||||
('€', 'EUR '),
|
||||
('\$', 'USD '),
|
||||
(r'\bKB\b', 'kilobytes'),
|
||||
(r'\bMB\b', 'megabytes'),
|
||||
@@ -41,7 +41,7 @@ def calc(phenny, input):
|
||||
precision = 5
|
||||
if query[-3:] in ('GBP', 'USD', 'EUR', 'NOK'):
|
||||
precision = 2
|
||||
query = web.urllib.quote(query.encode('utf-8'))
|
||||
query = web.quote(query)
|
||||
|
||||
uri = 'http://futureboy.us/fsp/frink.fsp?fromVal='
|
||||
bytes = web.get(uri + query)
|
||||
@@ -71,18 +71,18 @@ def c(phenny, input):
|
||||
"""Google calculator."""
|
||||
if not input.group(2):
|
||||
return phenny.reply("Nothing to calculate.")
|
||||
q = input.group(2).encode('utf-8')
|
||||
q = input.group(2)
|
||||
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))
|
||||
bytes = web.get(uri + web.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 = ''.join(chr(ord(c)) for c in answer)
|
||||
answer = answer.decode('utf-8')
|
||||
answer = answer.replace(u'\xc2\xa0', ',')
|
||||
answer = answer.replace('\xc2\xa0', ',')
|
||||
answer = answer.replace('<sup>', '^(')
|
||||
answer = answer.replace('</sup>', ')')
|
||||
answer = web.decode(answer)
|
||||
@@ -92,9 +92,9 @@ c.commands = ['c']
|
||||
c.example = '.c 5 + 3'
|
||||
|
||||
def py(phenny, input):
|
||||
query = input.group(2).encode('utf-8')
|
||||
query = input.group(2)
|
||||
uri = 'http://tumbolia.appspot.com/py/'
|
||||
answer = web.get(uri + web.urllib.quote(query))
|
||||
answer = web.get(uri + web.quote(query))
|
||||
if answer:
|
||||
phenny.say(answer)
|
||||
else: phenny.reply('Sorry, no result.')
|
||||
@@ -103,13 +103,13 @@ py.commands = ['py']
|
||||
def wa(phenny, input):
|
||||
if not input.group(2):
|
||||
return phenny.reply("No search term.")
|
||||
query = input.group(2).encode('utf-8')
|
||||
query = input.group(2)
|
||||
uri = 'http://tumbolia.appspot.com/wa/'
|
||||
answer = web.get(uri + web.urllib.quote(query.replace('+', '%2B')))
|
||||
answer = web.get(uri + web.quote(query.replace('+', '%2B')))
|
||||
if answer:
|
||||
phenny.say(answer)
|
||||
else: phenny.reply('Sorry, no result.')
|
||||
wa.commands = ['wa']
|
||||
|
||||
if __name__ == '__main__':
|
||||
print __doc__.strip()
|
||||
print(__doc__.strip())
|
||||
|
||||
Reference in New Issue
Block a user