From 4974f97f6bbb07512a078be994de54db9a62323b Mon Sep 17 00:00:00 2001 From: lemoer Date: Sat, 28 Dec 2024 16:53:02 +0100 Subject: [PATCH] add list_signal_groups.py --- list_signal_groups.py | 32 ++++++++++++++++++++++++++++++++ main.py | 12 ++++++------ 2 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 list_signal_groups.py diff --git a/list_signal_groups.py b/list_signal_groups.py new file mode 100644 index 0000000..6e5183d --- /dev/null +++ b/list_signal_groups.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +from main import config, SignalAPI +from result import is_err +import argparse + +if __name__ == "__main__": + api = SignalAPI(config.apiurl, config.number) + + parser = argparse.ArgumentParser(description='List all groups') + parser.add_argument('-i', "--show-group-ids", action='store_true', help='show group ids') + + args = parser.parse_args() + + 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) + diff --git a/main.py b/main.py index 01fb4d0..05ce808 100644 --- a/main.py +++ b/main.py @@ -526,14 +526,14 @@ async def main(config: Config, session: Session): bot.sync_members_and_tasks(session) ) +with open("config.json", "r") as f: + config = Config.model_validate(json.load(f)) + +engine = create_engine("sqlite:///data.db") +SQLModel.metadata.create_all(engine) + if __name__ == "__main__": - with open("config.json", "r") as f: - config = Config.model_validate(json.load(f)) - - engine = create_engine("sqlite:///data.db") - SQLModel.metadata.create_all(engine) - with Session(engine) as session: asyncio.run(main(config, session))