2024-12-28 16:53:02 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
from main import config, SignalAPI
|
|
|
|
from result import is_err
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='List all groups')
|
|
|
|
parser.add_argument('-i', "--show-group-ids", action='store_true', help='show group ids')
|
2024-12-28 23:46:13 +01:00
|
|
|
parser.add_argument('--api-url', type=str, default=None, help='API URL')
|
2024-12-28 16:53:02 +01:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2024-12-28 23:46:13 +01:00
|
|
|
if args.api_url is not None:
|
|
|
|
config.apiurl = args.api_url
|
|
|
|
|
|
|
|
api = SignalAPI(config.apiurl, config.number)
|
|
|
|
|
2024-12-28 16:53:02 +01:00
|
|
|
groups_result = api.get_groups()
|
|
|
|
|
|
|
|
if is_err(groups_result):
|
|
|
|
print("Error: " + groups_result.unwrap_err())
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
groups = groups_result.unwrap()
|
|
|
|
|
|
|
|
for group in groups:
|
|
|
|
suffix = ""
|
|
|
|
if api.number in group.admins:
|
|
|
|
suffix = " (admin)"
|
|
|
|
|
|
|
|
print(group.name + suffix)
|
|
|
|
|
|
|
|
if args.show_group_ids:
|
|
|
|
print(" id: " + group.id)
|
|
|
|
|