halcy / Mastodon.py

Python wrapper for the Mastodon ( https://github.com/mastodon/mastodon/ ) API.
MIT License
876 stars 150 forks source link

[question] retrieving most recent status for a user #372

Closed zcutlip closed 7 months ago

zcutlip commented 7 months ago

Hello, I'm back with more questions

I'm trying to retrieve the most recent status for a user (actually for myself)

  1. I've noticed that If I call account_statuses() with exclude_replies=True, I still get statuses that are replies. Do "replies" mean to other people? Or should that include threads as well?
In [2]: mast = Mastodon(api_base_url="https://botsin.space")

In [3]: user = mast.account_lookup("@zcutlip@hachyderm.io")

In [4]: statuses = mast.account_statuses(user.id, exclude_replies=True)

In [5]: for s in statuses:
   ...:     if s.in_reply_to_id:
   ...:         print(s.id)
   ...:         print(s.in_reply_to_id)
   ...:         print("")
   ...:
111973099963722789
111973093901599799

111965581127831887
111965563030616946

111965563030616946
111965548516793753
  1. I guess this is more a Mastodon API question, so apologies. I noticed I get status back in reverse chronological order. That's ideal for me, I actually only want the most recent one. Is that ordering reliable?
  2. All I actually want is to get my bot's most recent public status update, so I can schedule the next one according to the instance's rules. Am I making this too complicated?
halcy commented 7 months ago
  1. Huh! Maybe if it's a self-reply it doesn't include it, or it's a bug. I will have to investigate

  2. Yes, it's always newest first. For specifically Mastodon, they're ordered by ID, largest to smallest, and IDs are increasing (they're "Flake IDs" for masto, and in fact approximately relate to time). For *oma or other remotes, IDs may differ, but the posts still will, if the implementation is at all sensible, be in that order.

  3. Seems like a perfectly sensible design to me 🤷‍♂️

zcutlip commented 7 months ago

Awesome! Thanks for the clarification