Workflow-App/Workflow/scripts/_inspect_collection.py

38 lines
1.3 KiB
Python
Raw Permalink Normal View History

import os, sys, pathlib
import requests
import json
env_path = pathlib.Path(r'C:\Users\SJ\.minimax-agent\projects\Workflow\.env.local')
for line in env_path.read_text().splitlines():
if line.strip() and '=' in line and not line.startswith('#'):
k, v = line.split('=', 1)
os.environ.setdefault(k.strip(), v.strip())
url = os.environ['PB_URL']
token = os.environ['PB_TOKEN']
headers = {'Authorization': f'Bearer {token}'}
# Get the EMP201 collection
coll_id = 'pbc_2178038841'
# Get collection schema
r = requests.get(f'{url}/api/collections/{coll_id}', headers=headers, timeout=15)
r.raise_for_status()
coll = r.json()
print('=== COLLECTION ===')
print(f' name: {coll.get("name")}')
print(f' id: {coll.get("id")}')
print(f' system: {coll.get("system")}')
print(f' schema: {json.dumps(coll.get("schema", {}), indent=2)}')
print(f' indexes: {json.dumps(coll.get("indexes", []), indent=2)}')
print()
# Get a sample record to see actual fields
r = requests.get(f'{url}/api/collections/{coll_id}/records', headers=headers, params={'perPage': 3}, timeout=15)
r.raise_for_status()
items = r.json().get('items', [])
print(f'=== SAMPLE RECORDS ({len(items)}) ===')
for i, rec in enumerate(items):
print(f'\n--- record {i+1} ---')
print(json.dumps(rec, indent=2, default=str))