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])