From 063d3b7869880f79461d3bb0565d16008806b0b5 Mon Sep 17 00:00:00 2001 From: b3yond Date: Sun, 23 Jul 2017 14:40:30 +0200 Subject: [PATCH 1/6] CRLF missing in log format, experimenting with twitter api rate limit --- retootbot.py | 2 +- retweetbot.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/retootbot.py b/retootbot.py index 48c91ac..e52a6b4 100644 --- a/retootbot.py +++ b/retootbot.py @@ -41,7 +41,7 @@ class RetootBot(object): message = message + " The traceback is located at " + os.path.join("logs" + time) with open(os.path.join("logs", time), 'w+') as f: f.write(tb) - line = "[" + time + "] "+ message + line = "[" + time + "] "+ message + "\n" with open(self.logpath, 'a') as f: f.write(line) print line diff --git a/retweetbot.py b/retweetbot.py index fbae911..c8fe866 100644 --- a/retweetbot.py +++ b/retweetbot.py @@ -85,7 +85,7 @@ class RetweetBot(object): message = message + " The traceback is located at " + os.path.join("logs" + time) with open(os.path.join("logs", time), 'w+') as f: f.write(tb) - line = "[" + time + "] "+ message + line = "[" + time + "] "+ message + "\n" with open(self.logpath, 'a') as f: f.write(line) print line @@ -136,7 +136,7 @@ class RetweetBot(object): return mentions except twitter.TwitterError: self.log("Twitter API Error: Rate Limit Exceeded.") - sleep(60) + sleep(120) except requests.exceptions.ConnectionError: self.log("Twitter API Error: Bad Connection.") sleep(10) From 719685ce9c21c9ec2316fe9995df65f850a9cb99 Mon Sep 17 00:00:00 2001 From: b3yond Date: Sun, 23 Jul 2017 15:00:52 +0200 Subject: [PATCH 2/6] removed print of empty line in direct output --- retootbot.py | 2 +- retweetbot.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/retootbot.py b/retootbot.py index e52a6b4..1ac545e 100644 --- a/retootbot.py +++ b/retootbot.py @@ -44,7 +44,7 @@ class RetootBot(object): line = "[" + time + "] "+ message + "\n" with open(self.logpath, 'a') as f: f.write(line) - print line + print line, def register(self): self.client_id = os.path.join( diff --git a/retweetbot.py b/retweetbot.py index c8fe866..15a88eb 100644 --- a/retweetbot.py +++ b/retweetbot.py @@ -88,7 +88,7 @@ class RetweetBot(object): line = "[" + time + "] "+ message + "\n" with open(self.logpath, 'a') as f: f.write(line) - print line + print line, def get_history(self, path): """ This counter is needed to keep track of your mentions, so you From d1dc51abea7b12f631606e0e3fe759543a185bcb Mon Sep 17 00:00:00 2001 From: b3yond Date: Sun, 23 Jul 2017 15:47:23 +0200 Subject: [PATCH 3/6] lots of small stuff which hopefully helps --- README.md | 8 ++++++++ retweetbot.py | 2 +- ticketfrei.cfg.example | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0605a7f..83b1f98 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,14 @@ There is also a blacklist, which you can use to automatically sort out malicious Note that atm the good- & blacklist are still outside of ticketfrei.cfg, in separate files. we will repare this soon. +To keep the bots running when you are logged out of the shell, you can use screen: + +```shell +sudo apt-get install screen +screen +python ticketfrei.py +``` + ## ideas * You can only use the twitter API if you have confirmed a phone number and sacrificed a penguin in a blood ritual. So we should build it in a way that it uses the twitter web GUI. It's difficult, but maybe it works. We had another twitter bot that worked similarly, years ago: https://github.com/b3yond/twitter-bot diff --git a/retweetbot.py b/retweetbot.py index 15a88eb..ef5cd75 100644 --- a/retweetbot.py +++ b/retweetbot.py @@ -48,7 +48,7 @@ class RetweetBot(object): if logpath: self.logpath = logpath else: - self.logpath = os.path.join("logs", "{%Y-%m-%d_%H:%M:%S}".format(datetime.datetime.now())) + self.logpath = os.path.join("logs", str(datetime.datetime.now())) print "Path of logfile: " + self.logpath def get_api_keys(self): diff --git a/ticketfrei.cfg.example b/ticketfrei.cfg.example index d6d3d2f..39d9cf6 100644 --- a/ticketfrei.cfg.example +++ b/ticketfrei.cfg.example @@ -21,6 +21,7 @@ access_token_secret = "youraccesstokensecret" # goodlists are one regex per line. # badlists are one badword per line. # a message musst match at least one regex in goodlist and contain none of the badwords. +# the variables mention the directory where the lists are located, not the filenames. # goodlist_path = 'goodlists' # blacklist_path = 'blacklists' From c8e2efc848a0d3aa79500e19f101d532b8212995 Mon Sep 17 00:00:00 2001 From: b3yond Date: Sun, 23 Jul 2017 15:52:57 +0200 Subject: [PATCH 4/6] fixed sending DMs in shutdown() --- retweetbot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/retweetbot.py b/retweetbot.py index ef5cd75..adcfb0f 100644 --- a/retweetbot.py +++ b/retweetbot.py @@ -38,6 +38,7 @@ class RetweetBot(object): access_token_secret=keys[3]) self.historypath = historypath try: + self.no_shutdown_contact = False self.user_id = self.config['tapp']['shutdown_contact_userid'] self.screen_name = \ self.config['tapp']['shutdown_contact_screen_name'] From 1833986565204af8f4695219fb5af98cd6910130 Mon Sep 17 00:00:00 2001 From: b3yond Date: Tue, 25 Jul 2017 15:00:57 +0200 Subject: [PATCH 5/6] 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, From 3eb9321c53939d689203ba261e96e4152d8a8089 Mon Sep 17 00:00:00 2001 From: b3yond Date: Tue, 25 Jul 2017 15:13:54 +0200 Subject: [PATCH 6/6] reverted so called "fix" and try-excepted the problem --- retootbot.py | 10 +++++++--- retweetbot.py | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/retootbot.py b/retootbot.py index 75df2a5..b655750 100644 --- a/retootbot.py +++ b/retootbot.py @@ -39,11 +39,15 @@ 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, encoding='utf-8'), 'w+') as f: + with open(os.path.join("logs", time), 'w+') as f: f.write(tb) line = "[" + time + "] "+ message + "\n" - with open(self.logpath, 'a', encoding='utf-8') as f: - f.write(line) + with open(self.logpath, 'a') as f: + try: + f.write(line) + except UnicodeEncodeError: + self.log("Failed to save log message due to UTF-8 error. ") + traceback.print_exc() print line, def register(self): diff --git a/retweetbot.py b/retweetbot.py index a60e071..aab66c7 100644 --- a/retweetbot.py +++ b/retweetbot.py @@ -85,11 +85,15 @@ 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, encoding='utf-8'), 'w+') as f: + with open(os.path.join("logs", time), 'w+') as f: f.write(tb) line = "[" + time + "] "+ message + "\n" - with open(self.logpath, 'a', encoding='utf-8') as f: - f.write(line) + with open(self.logpath, 'a') as f: + try: + f.write(line) + except UnicodeEncodeError: + self.log("Failed to save log message due to UTF-8 error. ") + traceback.print_exc() print line, def get_history(self, path):