From 5354d0d0fad968c0945ed6a7f1e238db1cd0aeb6 Mon Sep 17 00:00:00 2001 From: b3yond Date: Wed, 19 Jul 2017 12:32:32 +0200 Subject: [PATCH] fixed the problem with saving last_mention. Yay! --- retweetbot.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/retweetbot.py b/retweetbot.py index 12cd11f..4015c79 100644 --- a/retweetbot.py +++ b/retweetbot.py @@ -79,9 +79,10 @@ class RetweetBot(object): with open(path, "r+") as f: last_mention = f.read() except IOError: - with open(path, "w+"): - last_mention = "" - return last_mention + with open(path, "w+") as f: + last_mention = "0" + f.write(last_mention) + return int(last_mention) def save_last_mention(self): """ Saves the last retweeted tweet in last_mention. """ @@ -133,11 +134,13 @@ class RetweetBot(object): # maybe one day we get rid of this error. If not, try to uncomment # these lines. except twitter.error.TwitterError: - print("[ERROR] probably you already retweeted this tweet.") + traceback.print_exc() + print("[ERROR] probably you already retweeted this tweet: " + status.text) if status.id > self.last_mention: self.last_mention = status.id return None except requests.exceptions.ConnectionError: + traceback.print_exc() print("[ERROR] Bad Connection.") sleep(10) @@ -154,6 +157,7 @@ class RetweetBot(object): self.api.PostUpdate(status=post) return except requests.exceptions.ConnectionError: + traceback.print_exc() print("[ERROR] Bad Connection.") sleep(10) @@ -181,7 +185,8 @@ class RetweetBot(object): mastodon.append(toot) # save the id so it doesn't get crawled again - print status.id, self.last_mention # debug + if status.id > self.last_mention: + self.last_mention = status.id self.save_last_mention() # Return Retweets for tooting on mastodon return mastodon