add list_signal_groups.py

This commit is contained in:
lemoer 2024-12-28 16:53:02 +01:00
parent e6b8a0445c
commit 4974f97f6b
2 changed files with 38 additions and 6 deletions

32
list_signal_groups.py Normal file
View File

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

View File

@ -526,14 +526,14 @@ async def main(config: Config, session: Session):
bot.sync_members_and_tasks(session) bot.sync_members_and_tasks(session)
) )
if __name__ == "__main__":
with open("config.json", "r") as f: with open("config.json", "r") as f:
config = Config.model_validate(json.load(f)) config = Config.model_validate(json.load(f))
engine = create_engine("sqlite:///data.db") engine = create_engine("sqlite:///data.db")
SQLModel.metadata.create_all(engine) SQLModel.metadata.create_all(engine)
if __name__ == "__main__":
with Session(engine) as session: with Session(engine) as session:
asyncio.run(main(config, session)) asyncio.run(main(config, session))