Skip to content

Commit

Permalink
Merge pull request #25 from dhjw/pinned
Browse files Browse the repository at this point in the history
Support pulling pinned statuses
  • Loading branch information
lxcode authored Dec 13, 2023
2 parents b11c5b2 + dd8e273 commit 0ae76a4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion truthbrush/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def pull_statuses(
verbose=False,
created_after: datetime = None,
since_id=None,
pinned=False,
) -> List[dict]:
"""Pull the given user's statuses.
Expand All @@ -278,7 +279,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("--------------------------")
Expand Down Expand Up @@ -314,6 +317,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()

Expand Down
9 changes: 7 additions & 2 deletions truthbrush/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,19 @@ 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
if created_after and created_after.tzinfo is 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))

0 comments on commit 0ae76a4

Please sign in to comment.