From 34d6b8f3a772bd125286189b9cfc1abf63b37a6a Mon Sep 17 00:00:00 2001 From: EthanC <16727756+EthanC@users.noreply.github.com> Date: Mon, 4 Mar 2024 02:58:41 -0600 Subject: [PATCH] Fix for null postId, README adjustment --- README.md | 2 +- services/x.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2412d9d..9056b1d 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Bluebird monitors users on X and reports new posts via Discord. Although not required, a [Discord Webhook](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks) is recommended for notifications. -An X account is required for API credentials. It is recommended to use a throwaway account due to use of the internal API. +An X account is required. It is recommended to use a throwaway account due to use of the internal API. **Environment Variables:** diff --git a/services/x.py b/services/x.py index d82f096..996ccfb 100644 --- a/services/x.py +++ b/services/x.py @@ -189,9 +189,18 @@ def GetUserPosts( continue + postId: str | None = result.get("rest_id") + + # rest_id is sometimes within a tweet object. + if not postId: + postId = result.get("tweet", {}).get("rest_id") + + if not postId: + raise Exception("rest_id is null") + posts.append( { - "postId": int(result["rest_id"]), + "postId": postId, "timestamp": int( datetime.strptime( result["legacy"]["created_at"],