From 5c6b39e89f6bef2717046bee963dfeaae80de327 Mon Sep 17 00:00:00 2001 From: dhjw Date: Thu, 7 Dec 2023 20:43:10 -0800 Subject: [PATCH 1/2] Support pulling pinned statuses --- truthbrush/api.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/truthbrush/api.py b/truthbrush/api.py index c3142a6..525c235 100644 --- a/truthbrush/api.py +++ b/truthbrush/api.py @@ -260,12 +260,14 @@ def pull_statuses( verbose=False, created_after: datetime = None, since_id=None, + pinned=False, ) -> List[dict]: """Pull the given user's statuses. Params: created_after : timezone aware datetime object since_id : number or string + pinned : get pinned posts only Returns a list of posts in reverse chronological order, or an empty list if not found. @@ -278,7 +280,9 @@ def pull_statuses( while keep_going: try: url = f"/v1/accounts/{user_id}/statuses" - if not replies: + if pinned: + url += "?pinned=true&with_muted=true" + elif not replies: url += "?exclude_replies=true" if verbose: logger.debug("--------------------------") @@ -314,6 +318,9 @@ def pull_statuses( if verbose: logger.debug(f"PAGE: {page_counter}") + if pinned: # assume single page + keep_going = False + for post in posts: post["_pulled"] = datetime.now().isoformat() From dd8e273098cd30f9d28c15de0110c5a36808dd92 Mon Sep 17 00:00:00 2001 From: dhjw Date: Thu, 7 Dec 2023 21:25:22 -0800 Subject: [PATCH 2/2] Support pulling pinned statuses --- truthbrush/api.py | 1 - truthbrush/cli.py | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/truthbrush/api.py b/truthbrush/api.py index 525c235..34310b9 100644 --- a/truthbrush/api.py +++ b/truthbrush/api.py @@ -267,7 +267,6 @@ def pull_statuses( Params: created_after : timezone aware datetime object since_id : number or string - pinned : get pinned posts only Returns a list of posts in reverse chronological order, or an empty list if not found. diff --git a/truthbrush/cli.py b/truthbrush/cli.py index dfcbed5..305e1ee 100644 --- a/truthbrush/cli.py +++ b/truthbrush/cli.py @@ -115,7 +115,12 @@ def ads(): help="Only pull posts created on or after the specified datetime, e.g. 2021-10-02 or 2011-11-04T00:05:23+04:00 (defaults to none). If a timezone is not specified, UTC is assumed.", type=datetime.datetime.fromisoformat, ) -def statuses(username: str, replies: bool = False, created_after: date = None): +@click.option( + "--pinned/--all", + default=False, + help="Only pull pinned posts (defaults to all)" +) +def statuses(username: str, replies: bool = False, created_after: date = None, pinned: bool = False): """Pull a user's statuses""" # Assume UTC if no timezone is specified @@ -123,6 +128,6 @@ def statuses(username: str, replies: bool = False, created_after: date = None): created_after = created_after.replace(tzinfo=datetime.timezone.utc) for page in api.pull_statuses( - username, created_after=created_after, replies=replies + username, created_after=created_after, replies=replies, pinned=pinned ): print(json.dumps(page))