From 66bc030cb0294b9d08dc2c5ced262a5a830e1d8e Mon Sep 17 00:00:00 2001 From: uvok Date: Sun, 19 Jan 2025 18:30:41 +0100 Subject: Finish Mastodon API --- hello-fusepy.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/hello-fusepy.py b/hello-fusepy.py index ff9fd42..2c2d430 100644 --- a/hello-fusepy.py +++ b/hello-fusepy.py @@ -24,6 +24,7 @@ class APIChoice(enum.Enum): api_url_ap_template = "https://{server}/users/{user}/outbox?page=true" api_url_m_lookup_template = "https://{server}/api/v1/accounts/lookup" +api_url_m_status_template = "https://{server}/api/v1/accounts/{uid}/statuses" class Status(object): @@ -52,7 +53,6 @@ class ActivityPubStatusProvider(StatusProvider): res.raise_for_status() stats = res.json() - logging.debug(f"Status: ${stats['id']}") return [ Status( s["object"]["id"].split("/")[-1], @@ -78,7 +78,20 @@ class MastodonStatusProvider(StatusProvider): res.raise_for_status() user = res.json() self.userid = user["id"] - return self._fallback_not_found() + + url = api_url_m_status_template.format(server=self.server, uid=urllib.parse.quote(self.userid)) + res = requests.get(url) + if res.status_code == 404: + return self._fallback_not_found() + statuses = res.json() + return [ + Status( + s["id"], + s["content"], + s["created_at"], + ) + for s in statuses + ] class HelloWorld(Operations, LoggingMixIn): def __init__(self, api: APIChoice, server: str, user: str): @@ -180,6 +193,6 @@ def main(args): if __name__ == "__main__": - logging.basicConfig(level=logging.DEBUG) + #logging.basicConfig(level=logging.DEBUG) args = parse_arguments() main(args) -- cgit v1.2.3