Files
Brancheneinstufung2/connector-superoffice/tools/final_vertical_discovery.py

67 lines
2.3 KiB
Python

import sys
import os
import json
# Absolute path to the connector-superoffice directory
current_dir = os.path.dirname(os.path.abspath(__file__))
connector_dir = os.path.abspath(os.path.join(current_dir, '..'))
# CRITICAL: Insert at 0 to shadow /app/config.py
sys.path.insert(0, connector_dir)
from superoffice_client import SuperOfficeClient
def discover_verticals():
print("🔎 Starting Final Vertical Discovery (Production)...")
client = SuperOfficeClient()
if not client.access_token:
print("❌ Auth failed.")
return
# 1. Fetch Contact UDF Layout to find the List ID behind SuperOffice:83
print("📡 Fetching Contact UDF Layout (Metadata)...")
layout = client._get("Contact/UdefLayout/Published")
list_id = None
if layout and 'Fields' in layout:
for field in layout['Fields']:
if field.get('ProgId') == 'SuperOffice:83':
print(f"✅ Found SuperOffice:83: {field.get('Label')}")
list_id = field.get('ListId')
print(f"✅ List ID: {list_id}")
break
if not list_id:
print("❌ Could not find Metadata for SuperOffice:83.")
return
# 2. Fetch the List Items for this List
print(f"📡 Fetching List Items for List ID {list_id}...")
# List endpoint is typically List/ListId/Items
# Let's try to get all rows for this list
items = client._get(f"List/{list_id}/Items")
if items:
print(f"✅ SUCCESS! Found {len(items)} items in the Vertical list.")
mapping = {}
for item in items:
name = item.get('Value') or item.get('Name')
item_id = item.get('Id')
mapping[name] = item_id
print(f" - {name}: {item_id}")
print("\n🚀 FINAL MAPPING JSON (Copy to .env VERTICAL_MAP_JSON):")
print(json.dumps(mapping))
else:
print(f"❌ Could not fetch items for List {list_id}. Trying MDO List...")
# Fallback to MDO List
mdo_items = client._get(f"MDOList/udlist{list_id}")
if mdo_items:
print("✅ Success via MDO List.")
# ... process mdo items if needed ...
else:
print("❌ MDO List fallback failed too.")
if __name__ == "__main__":
discover_verticals()