[2ff88f42] feat(connector-superoffice): Implement Company Explorer sync and Holiday logic

- **Company Explorer Sync**: Added `explorer_client.py` and integrated Step 9 in `main.py` for automated data transfer to the intelligence engine.
- **Holiday Logic**: Implemented `BusinessCalendar` in `utils.py` using the `holidays` library to automatically detect weekends and Bavarian holidays, ensuring professional timing for automated outreaches.
- **API Discovery**: Created `parse_ce_openapi.py` to facilitate technical field mapping through live OpenAPI analysis.
- **Project Stability**: Refined error handling and logging for a smooth end-to-end workflow.
This commit is contained in:
2026-02-10 11:56:44 +00:00
parent b7265ff1e7
commit fd5ca41e7f
6 changed files with 223 additions and 20 deletions

View File

@@ -3,6 +3,7 @@ import logging
from dotenv import load_dotenv
from auth_handler import AuthHandler
from superoffice_client import SuperOfficeClient
from explorer_client import CompanyExplorerClient
# Setup logging
logging.basicConfig(
@@ -29,6 +30,9 @@ def main():
# Initialize Client
client = SuperOfficeClient(auth)
# Initialize Explorer Client
ce_client = CompanyExplorerClient()
# 1. Test Connection
logger.info("Step 1: Testing connection...")
user_info = client.test_connection()
@@ -38,15 +42,24 @@ def main():
logger.error("Connection test failed.")
return
# 1b. Test Company Explorer Connection
logger.info("Step 1b: Testing Company Explorer connection...")
if ce_client.check_health():
logger.info("Company Explorer is reachable.")
else:
logger.warning("Company Explorer is NOT reachable. Sync might fail.")
# 2. Search for our demo company
demo_company_name = "Gemini Test Company [2ff88f42]"
logger.info(f"Step 2: Searching for company '{demo_company_name}'...")
contact = client.find_contact_by_criteria(name=demo_company_name)
target_contact_id = None
contact_obj = None # Store the full contact object
if contact:
target_contact_id = contact.get('ContactId')
contact_obj = contact
logger.info(f"Found existing demo company: {contact.get('Name')} (ID: {target_contact_id})")
else:
logger.info(f"Demo company not found. Creating new one...")
@@ -60,8 +73,12 @@ def main():
)
if new_contact:
target_contact_id = new_contact.get('ContactId')
contact_obj = new_contact
logger.info(f"Created new demo company with ID: {target_contact_id}")
# ... (Steps 3-7 remain the same, I will insert the sync step at the end) ...
# 3. Create a Person linked to this company
if target_contact_id:
logger.info(f"Step 3: Creating Person for Contact ID {target_contact_id}...")
@@ -134,6 +151,24 @@ def main():
else:
logger.error("Failed to update Person UDFs.")
# 9. Sync to Company Explorer
if updated_contact:
logger.info(f"Step 9: Syncing Company to Company Explorer...")
ce_payload = {
"name": updated_contact.get("Name"),
"website": updated_contact.get("UrlAddress"),
"city": updated_contact.get("City"),
"country": "DE" # Defaulting to DE for now
}
ce_result = ce_client.import_company(ce_payload)
if ce_result:
logger.info(f"SUCCESS: Company synced to Explorer! ID: {ce_result.get('id')}")
else:
logger.error("Failed to sync company to Explorer.")
else:
logger.warning("Skipping CE sync because contact update failed or contact object is missing.")
else:
logger.error("Failed to create project.")