Wraps find_campaign_by_identifier() from update_campaign_status.py so operators can query a campaign's current DAM status by number or partial name without performing any updates. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
117 lines
3.8 KiB
Python
117 lines
3.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Campaign Status Check - Read-only lookup of a campaign's current status on the DAM
|
|
Searches all A#/B# statuses for a campaign by number or partial name and prints
|
|
the current status. Makes no changes.
|
|
Compatible with Python 3.6+
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import logging
|
|
import argparse
|
|
|
|
# Add shared library to path
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
from shared.config_loader import load_config
|
|
from shared.dam_client import DAMClient
|
|
from scripts.update_campaign_status import find_campaign_by_identifier
|
|
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
)
|
|
|
|
logger = logging.getLogger('CheckStatus')
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(
|
|
description='Check the current status of a campaign on the DAM (read-only)',
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
epilog="""
|
|
Examples:
|
|
# Check campaign C000000078 (dev environment, OAuth)
|
|
python scripts/check_campaign_status.py --camp C000000078
|
|
|
|
# Check by partial name
|
|
python scripts/check_campaign_status.py --camp "CONTENT SCALING"
|
|
|
|
# Production environment with mTLS V2
|
|
python scripts/check_campaign_status.py --camp C000000078 --auth-pfx-v2 --env prod
|
|
"""
|
|
)
|
|
parser.add_argument('--camp', type=str, required=True,
|
|
help='Campaign number (e.g., C000000078) or partial campaign name')
|
|
parser.add_argument('--auth-pfx', action='store_true',
|
|
help='Use mTLS certificate authentication (Legacy APIM)')
|
|
parser.add_argument('--auth-pfx-v2', action='store_true',
|
|
help='Use mTLS V2 (Hybrid) authentication')
|
|
parser.add_argument('--env', type=str, choices=['dev', 'prod'], default='dev',
|
|
help='Environment: dev (default) or prod')
|
|
args = parser.parse_args()
|
|
|
|
auth_mode = 'oauth'
|
|
if args.auth_pfx_v2:
|
|
auth_mode = 'mtls_v2'
|
|
elif args.auth_pfx:
|
|
auth_mode = 'mtls'
|
|
|
|
os.environ['ENV'] = args.env
|
|
|
|
print("")
|
|
print("=" * 70)
|
|
print("Ferrero Campaign Status Check")
|
|
print("=" * 70)
|
|
print("Campaign Identifier: {}".format(args.camp))
|
|
print("Environment: {}".format(args.env.upper()))
|
|
if auth_mode == 'mtls_v2':
|
|
print("Authentication: mTLS V2 (Hybrid)")
|
|
elif auth_mode == 'mtls':
|
|
print("Authentication: mTLS Certificate (Legacy)")
|
|
else:
|
|
print("Authentication: OAuth2 (default)")
|
|
print("=" * 70)
|
|
print("")
|
|
|
|
config = load_config('config/config.yaml')
|
|
dam = DAMClient(config, auth_mode=auth_mode)
|
|
|
|
logger.info("Testing DAM connection...")
|
|
if not dam.test_connection():
|
|
logger.error("DAM connection failed - exiting")
|
|
sys.exit(1)
|
|
logger.info("DAM connection OK")
|
|
print("")
|
|
|
|
campaigns = find_campaign_by_identifier(dam, args.camp)
|
|
|
|
if not campaigns:
|
|
print("")
|
|
print("=" * 70)
|
|
print("No campaigns found matching: {}".format(args.camp))
|
|
print("=" * 70)
|
|
print("")
|
|
print("Searched statuses: A1, A2, A3, A4, A5, A6, B1, B2")
|
|
print("Try:")
|
|
print(" - Exact campaign number: C000000078")
|
|
print(" - Partial campaign name: CONTENT SCALING")
|
|
sys.exit(1)
|
|
|
|
print("")
|
|
print("=" * 70)
|
|
print("Found {} matching campaign(s)".format(len(campaigns)))
|
|
print("=" * 70)
|
|
print("")
|
|
|
|
for i, campaign in enumerate(campaigns, 1):
|
|
print("{}. {}".format(i, campaign.get('campaign_name', 'Unknown')))
|
|
print(" Campaign Number: {}".format(campaign.get('campaign_id', 'N/A')))
|
|
print(" Current Status: {}".format(campaign['current_status']))
|
|
print(" DAM Asset ID: {}".format(campaign.get('asset_id', 'N/A')))
|
|
print("")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|