diff options
| author | Magnus Hagander | 2022-10-05 14:53:41 +0000 |
|---|---|---|
| committer | Magnus Hagander | 2022-10-05 15:00:28 +0000 |
| commit | cd02c43bfb330c210d196f007f9c1361d5f90f81 (patch) | |
| tree | 53889875f07a7a620ba40f2aa80d9754b5f19c37 | |
| parent | a079e1919feb4bc1b53aa0445255bfb50f12835d (diff) | |
Store the id of the tweet when a post has been tweeted
| -rwxr-xr-x | posttotwitter.py | 10 | ||||
| -rw-r--r-- | 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) @@ -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 ); |
