Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pulling pinned statuses #25

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))