#!/usr/bin/env python3 """ Test script to verify duplicate detection works correctly This will check if a deliverable with a specific OMG# exists in the LGL Team board """ import requests # Configuration API_TOKEN = "eyJ0dCI6InAiLCJhbGciOiJIUzI1NiIsInR2IjoiMiJ9.eyJkIjoie1wiYVwiOjY5NjM3MzksXCJpXCI6OTU5MTM2MSxcImNcIjo0NzAyNjA1LFwidVwiOjIzMjcyNDA0LFwiclwiOlwiVVNcIixcInNcIjpbXCJXXCIsXCJGXCIsXCJJXCIsXCJVXCIsXCJLXCIsXCJDXCIsXCJEXCIsXCJNXCIsXCJBXCIsXCJMXCIsXCJQXCJdLFwielwiOltdLFwidFwiOjB9IiwiaWF0IjoxNzY2MDAwNjMyfQ.FwtNCIiBUbb82MlEnI_Z3vKt-W8IgKRwLwZY6IY6fEI" API_BASE = "https://www.wrike.com/api/v4" SPACE_ID = "MQAAAABoHcTY" # LGL Team OMG_NUMBER_FIELD_ID = "IEAGUQQ3JUAJL7YF" def make_request(endpoint): """Make a GET request to Wrike API""" url = f"{API_BASE}{endpoint}" headers = { "Authorization": f"Bearer {API_TOKEN}", "Content-Type": "application/json" } try: response = requests.get(url, headers=headers, timeout=30) response.raise_for_status() return response.json() except requests.exceptions.RequestException as e: print(f"āŒ API Error: {e}") return None def find_deliverable_by_omg(folder_id, omg_number): """Find deliverable with matching OMG number""" print(f"\nšŸ” Searching for deliverable with OMG# {omg_number} in folder {folder_id}...") # Get all subfolders/projects result = make_request(f"/folders/{folder_id}/folders") if result and "data" in result: # Find parent folder with childIds parent_folder = None for item in result["data"]: if item["id"] == folder_id: parent_folder = item break if parent_folder: child_ids = parent_folder.get("childIds", []) print(f" Found {len(child_ids)} child items to check") # For each child, get its details with custom fields for child_id in child_ids: child_result = make_request(f"/folders/{child_id}") if child_result and "data" in child_result and len(child_result["data"]) > 0: child = child_result["data"][0] # Check if it's a project (deliverable) if "project" in child: custom_fields = child.get("customFields", []) for field in custom_fields: if field.get("id") == OMG_NUMBER_FIELD_ID: field_value = field.get("value") if field_value == omg_number: print(f" āœ… FOUND: '{child['title']}' (ID: {child_id}) has OMG# {field_value}") return child_id else: print(f" - '{child['title']}' has OMG# {field_value} (doesn't match)") print(f" āŒ NOT FOUND: No deliverable with OMG# {omg_number}") return None def list_recent_deliverables_with_omg(space_id): """List some existing deliverables with their OMG numbers""" print(f"\nšŸ“‹ Listing existing deliverables with OMG# in space {space_id}...") print("="*80) # Get top-level folders in space result = make_request(f"/folders/{space_id}/folders") if result and "data" in result: # Find space folder with childIds space_folder = None for item in result["data"]: if item["id"] == space_id: space_folder = item break if space_folder: child_ids = space_folder.get("childIds", [])[:5] # Limit to first 5 folders for folder_id in child_ids: folder_result = make_request(f"/folders/{folder_id}/folders") if folder_result and "data" in folder_result: for item in folder_result["data"]: if "project" in item: custom_fields = item.get("customFields", []) for field in custom_fields: if field.get("id") == OMG_NUMBER_FIELD_ID: omg_value = field.get("value", "N/A") print(f" • {item['title']}") print(f" OMG#: {omg_value}") print(f" ID: {item['id']}") print() def main(): print(""" ╔════════════════════════════════════════════════════════════════╗ ā•‘ DUPLICATE DETECTION TEST ā•‘ ā•‘ Verifies that the script can find existing deliverables ā•‘ ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā• """) # List some existing deliverables list_recent_deliverables_with_omg(SPACE_ID) # Test duplicate detection print("\n" + "="*80) print("TESTING DUPLICATE DETECTION") print("="*80) # You can test with a known OMG# from the list above test_omg = input("\nEnter an OMG# to test (or press Enter to skip): ").strip() if test_omg: # You'll need to provide a folder ID to search in test_folder = input("Enter the folder/project ID to search in: ").strip() if test_folder: result = find_deliverable_by_omg(test_folder, test_omg) if result: print(f"\nāœ… SUCCESS: Duplicate detection would catch this!") print(f" The script would SKIP creating a new deliverable") print(f" and use existing ID: {result}") else: print(f"\nāœ… SUCCESS: OMG# {test_omg} not found") print(f" The script would CREATE a new deliverable") if __name__ == "__main__": main()