Files
2026-07-19 17:52:14 +03:00

41 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python3
"""Read Social Accounts from the Muninn API.
Usage:
python3 accounts.py list [--network NETWORK] [--type TYPE]
python3 accounts.py get ACCOUNT_ID
Base URL defaults to http://localhost:8001, override with the
MUNINN_API_URL environment variable.
"""
import argparse
import _client
NETWORKS = ["twitter", "instagram", "facebook", "reddit", "tiktok", "linkedin", "youtube", "other"]
TYPES = ["post", "comment", "like"]
def main() -> None:
parser = argparse.ArgumentParser(description="Social Accounts API client")
subparsers = parser.add_subparsers(dest="command", required=True)
list_parser = subparsers.add_parser("list", help="List all social accounts")
list_parser.add_argument("--network", choices=NETWORKS, help="Exact match filter on network")
list_parser.add_argument("--type", choices=TYPES, help="Exact match filter on type")
get_parser = subparsers.add_parser("get", help="Get a single social account")
get_parser.add_argument("account_id", type=int)
args = parser.parse_args()
if args.command == "list":
_client.request("GET", "/api/accounts", params={"network": args.network, "type": args.type})
elif args.command == "get":
_client.request("GET", f"/api/accounts/{args.account_id}")
if __name__ == "__main__":
main()