From a2990eb8595977b0e1b07a990b24740733b8c8dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Vieira?= Date: Sat, 30 Jul 2016 11:49:04 +0100 Subject: [PATCH] Make logger work with both str and unicode log is sometimes called with str, other times with unicode sequences. This change makes it work for both cases. --- pokemongo_bot/logger.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/logger.py b/pokemongo_bot/logger.py index 054352c452..1ec7be0891 100644 --- a/pokemongo_bot/logger.py +++ b/pokemongo_bot/logger.py @@ -10,6 +10,11 @@ def log(string, color='white'): + try: + string = string.decode('utf8') + except UnicodeEncodeError: + pass + color_hex = { 'red': '91m', 'green': '92m', @@ -20,7 +25,7 @@ def log(string, color='white'): if color not in color_hex: print('[' + time.strftime("%H:%M:%S") + '] ' + string) else: - print('[' + time.strftime("%H:%M:%S") + '] ' + u'\033[' + color_hex[color] + string.decode('utf-8') + '\033[0m') + print('[' + time.strftime("%H:%M:%S") + '] ' + '\033[' + color_hex[color] + string + '\033[0m') if lcd: if string: lcd.message(string)