From b1b2ed1ff8eba7576b955ccfad2e9964c67d1478 Mon Sep 17 00:00:00 2001 From: chfour Date: Wed, 4 Mar 2026 21:01:54 +0100 Subject: [PATCH] use functools.cached_property and add naive mutes list naive in that it's not aware of pagination --- mute_sync.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/mute_sync.py b/mute_sync.py index 623c127..9b88a40 100644 --- a/mute_sync.py +++ b/mute_sync.py @@ -2,6 +2,7 @@ import httpx import typing import argparse import json +import functools class BearerAuth(httpx.Auth): @@ -21,15 +22,23 @@ class UserAccount: auth=BearerAuth(token['access_token']) ) - r_info = self.client.get('/api/v1/accounts/verify_credentials') - r_info.raise_for_status() - self.info = r_info.json() + @functools.cached_property + def info(self) -> dict: + r = self.client.get('/api/v1/accounts/verify_credentials') + r.raise_for_status() + return r.json() + + @functools.cached_property + def mutes(self) -> dict: + r = self.client.get('/api/v1/mutes') + r.raise_for_status() + return r.json() def __repr__(self) -> str: return f'' def __str__(self) -> str: - return f'{self.info["username"]}@{self.instance}' + return f'@{self.info["acct"]} ({self.instance})' if __name__ == '__main__': @@ -43,4 +52,8 @@ if __name__ == '__main__': args = parser.parse_args() accounts = [UserAccount(json.load(token_f)) for token_f in args.token_file] - print(accounts) + print('accounts:', ', '.join((str(acct) for acct in accounts))) + + for acct in accounts: + print(str(acct)) + print([mute_acct["acct"] for mute_acct in acct.mutes]) -- 2.51.2