#!/usr/bin/env python3 """CLI for posting Polaris notices via the Leap (PAPI) API. Usage: python post_notices.py --notice-type 8 --org-ids 3,5,7 """ import argparse import os import sys from dotenv import load_dotenv from polaris_client import PolarisAuthError, PolarisClient, PolarisRequestError def parse_args(): parser = argparse.ArgumentParser(description="Post notices to Polaris via the Leap API.") parser.add_argument( "--notice-type", type=int, required=True, help="Notification Type ID to post (see your Polaris system tables).", ) parser.add_argument( "--org-ids", required=True, help="Comma-separated list of Organization IDs, e.g. 3,5,7", ) parser.add_argument( "--delivery-option", type=int, default=1, help="Delivery Option ID. Only 1 (Mail) is currently supported by Polaris.", ) return parser.parse_args() def main(): load_dotenv() args = parse_args() required_env = [ "POLARIS_SERVER", "POLARIS_SITE_DOMAIN", "POLARIS_ORGANIZATION_ID", "POLARIS_WORKSTATION_ID", "POLARIS_USERNAME", "POLARIS_PASSWORD", ] missing = [name for name in required_env if not os.environ.get(name)] if missing: print(f"Missing required .env values: {', '.join(missing)}", file=sys.stderr) print("Copy .env.example to .env and fill it in.", file=sys.stderr) sys.exit(1) org_ids = [int(oid.strip()) for oid in args.org_ids.split(",") if oid.strip()] client = PolarisClient( server=os.environ["POLARIS_SERVER"], site_domain=os.environ["POLARIS_SITE_DOMAIN"], organization_id=os.environ["POLARIS_ORGANIZATION_ID"], workstation_id=os.environ["POLARIS_WORKSTATION_ID"], language=os.environ.get("POLARIS_LANGUAGE", "eng"), product_id=os.environ.get("POLARIS_PRODUCT_ID", "7"), ) try: client.authenticate(os.environ["POLARIS_USERNAME"], os.environ["POLARIS_PASSWORD"]) client.post_notices(args.notice_type, org_ids, args.delivery_option) except (PolarisAuthError, PolarisRequestError) as exc: print(f"Error: {exc}", file=sys.stderr) sys.exit(1) print( f"Notices posted successfully: noticeType={args.notice_type}, " f"orgIds={org_ids}, deliveryOption={args.delivery_option}" ) if __name__ == "__main__": main()