From 1833986565204af8f4695219fb5af98cd6910130 Mon Sep 17 00:00:00 2001 From: b3yond Date: Tue, 25 Jul 2017 15:00:57 +0200 Subject: [PATCH] fixed error with logging of utf-8 encoded logs --- retootbot.py | 4 ++-- retweetbot.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/retootbot.py b/retootbot.py index 1ac545e..75df2a5 100644 --- a/retootbot.py +++ b/retootbot.py @@ -39,10 +39,10 @@ class RetootBot(object): time = str(datetime.datetime.now()) if tb: message = message + " The traceback is located at " + os.path.join("logs" + time) - with open(os.path.join("logs", time), 'w+') as f: + with open(os.path.join("logs", time, encoding='utf-8'), 'w+') as f: f.write(tb) line = "[" + time + "] "+ message + "\n" - with open(self.logpath, 'a') as f: + with open(self.logpath, 'a', encoding='utf-8') as f: f.write(line) print line, diff --git a/retweetbot.py b/retweetbot.py index adcfb0f..a60e071 100644 --- a/retweetbot.py +++ b/retweetbot.py @@ -29,6 +29,7 @@ class RetweetBot(object): :param historypath: Path to the file with ID of the last retweeted Tweet + :param logpath: Path to the file where the log is stored """ self.config = config keys = self.get_api_keys() @@ -84,10 +85,10 @@ class RetweetBot(object): time = str(datetime.datetime.now()) if tb: message = message + " The traceback is located at " + os.path.join("logs" + time) - with open(os.path.join("logs", time), 'w+') as f: + with open(os.path.join("logs", time, encoding='utf-8'), 'w+') as f: f.write(tb) line = "[" + time + "] "+ message + "\n" - with open(self.logpath, 'a') as f: + with open(self.logpath, 'a', encoding='utf-8') as f: f.write(line) print line,