From c8e67d193769e9683756936d3b57d84616572b9f Mon Sep 17 00:00:00 2001 From: b3yond Date: Thu, 18 Jan 2018 15:10:05 +0100 Subject: [PATCH] better error handling of FileExistsError, fixed regex for mastobot --- retootbot.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/retootbot.py b/retootbot.py index 8b4ffdc..31e0ab4 100755 --- a/retootbot.py +++ b/retootbot.py @@ -59,8 +59,10 @@ class RetootBot(object): with os.fdopen(os.open('seen_toots.pickle.part', os.O_WRONLY | os.O_EXCL | os.O_CREAT), 'wb') as f: pickle.dump(self.seen_toots, f) except FileExistsError: - with os.fdopen(os.open('seen_toots.pickle.part', os.O_WRONLY), 'wb') as f: + os.unlink('seen_toots.pickle.part') + with os.fdopen(os.open('seen_toots.pickle.part', os.O_WRONLY | os.O_EXCL | os.O_CREAT), 'wb') as f: pickle.dump(self.seen_toots, f) + os.rename('seen_toots.pickle.part', 'seen_toots.pickle') def crawl(self): """ @@ -75,12 +77,12 @@ class RetootBot(object): # save state self.seen_toots.add(status['status']['id']) self.save_last() - os.rename('seen_toots.pickle.part', 'seen_toots.pickle') # add mention to mentions - text = re.sub("(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-_]+)", "", status['status']['content']) + text = re.sub(r'<[^>]*>', '', status['status']['content']) + text = re.sub("(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-_]+)", "", text) mentions.append(report.Report(status['account']['acct'], "mastodon", - re.sub(r'<[^>]*>', '', text), + text, status['status']['id'], status['status']['created_at'])) return mentions