more python3 fixes

master
mutantmonkey 2011-09-22 15:04:19 -04:00
parent baf5403066
commit 800b78a02f
5 changed files with 12 additions and 12 deletions

2
bot.py
View File

@ -228,7 +228,7 @@ class Phenny(irc.Bot):
t.start()
else: self.call(func, origin, phenny, input)
for source in [origin.sender, origin.nick]:
for source in [decode(origin.sender), decode(origin.nick)]:
try: self.stats[(func.name, source)] += 1
except KeyError:
self.stats[(func.name, source)] = 1

5
irc.py
View File

@ -52,6 +52,7 @@ class Bot(asynchat.async_chat):
def __write(self, args, text=None):
# print '%r %r %r' % (self, args, text)
print(args, text)
try:
if text is not None:
self.push((b' '.join(args) + b' :' + text)[:512] + b'\r\n')
@ -61,8 +62,7 @@ class Bot(asynchat.async_chat):
pass
def write(self, args, text=None):
print(args, text)
# This is a safe version of __write
"""This is a safe version of __write"""
def safe(input):
input = input.replace('\n', '')
input = input.replace('\r', '')
@ -118,6 +118,7 @@ class Bot(asynchat.async_chat):
def found_terminator(self):
line = self.buffer
print(line)
if line.endswith(b'\r'):
line = line[:-1]
self.buffer = b''

View File

@ -79,9 +79,8 @@ def c(phenny, input):
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 = ''.join(chr(ord(c)) for c in answer)
#answer = answer.decode('utf-8')
answer = answer.replace('\xc2\xa0', ',')
answer = answer.replace('<sup>', '^(')
answer = answer.replace('</sup>', ')')

View File

@ -220,10 +220,10 @@ def f_weather(self, origin, match, args):
description = 'Violent storm'
else: description = 'Hurricane'
degrees = float(wind[0:3]
if degrees == 'VRB':
degrees = '\u21BB'
elif (degrees <= 22.5) or (degrees > 337.5):
degrees = float(wind[0:3])
#if degrees == 'VRB':
# degrees = '\u21BB'
if (degrees <= 22.5) or (degrees > 337.5):
degrees = '\u2191'
elif (degrees > 22.5) and (degrees <= 67.5):
degrees = '\u2197'

4
phenny
View File

@ -17,8 +17,8 @@ from textwrap import dedent as trim
dotdir = os.path.expanduser('~/.phenny')
def check_python_version():
if sys.version_info < (2, 4):
error = 'Error: Requires Python 2.4 or later, from www.python.org'
if sys.version_info < (3, 0):
error = 'Error: Requires Python 3.0 or later, from www.python.org'
print(error, file=sys.stderr)
sys.exit(1)