From cd02c43bfb330c210d196f007f9c1361d5f90f81 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Wed, 5 Oct 2022 16:53:41 +0200 Subject: [PATCH] Store the id of the tweet when a post has been tweeted --- posttotwitter.py | 10 ++++++++-- schema.sql | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/posttotwitter.py b/posttotwitter.py index af37302..dccaaed 100755 --- a/posttotwitter.py +++ b/posttotwitter.py @@ -37,6 +37,9 @@ class PostToTwitter(TwitterClient): if r.status_code != 200: raise Exception("Could not post to twitter, status code {0}".format(r.status_code)) + # Return the id of the tweet + return r.json()['id'] + def Run(self): c = self.db.cursor() c.execute("""SELECT posts.id, posts.title, posts.link, posts.shortlink, feeds.name, feeds.twitteruser @@ -79,14 +82,17 @@ class PostToTwitter(TwitterClient): # Now post it to twitter try: - self.do_post(msg) + tweetid = self.do_post(msg) except Exception as e: print("Error posting to twitter (post %s): %s" % (post[0], e)) # We'll just try again with the next one continue # Flag this item as posted - c.execute("UPDATE posts SET twittered='t' WHERE id=%(id)s", {'id': post[0]}) + c.execute("UPDATE posts SET twittered='t', tweetid=%(tweetid)s WHERE id=%(id)s", { + 'id': post[0], + 'tweetid': tweetid, + }) self.db.commit() print("Twittered: %s" % msg) diff --git a/schema.sql b/schema.sql index 6e89762..e653783 100644 --- a/schema.sql +++ b/schema.sql @@ -64,6 +64,7 @@ CREATE TABLE posts ( guidisperma boolean NOT NULL, hidden boolean DEFAULT false NOT NULL, twittered boolean DEFAULT false NOT NULL, + tweetid int8 NULL, shortlink text ); -- 2.39.5