# %%
from ibm_watson import DiscoveryV2
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
import json
# %%
apikey='APIKEY'
version='VERSION'
authenticator = IAMAuthenticator(apikey=apikey)
discovery = DiscoveryV2(version=version, authenticator=authenticator)
# %%
service_url='SERVICE_URL'
discovery.set_service_url(service_url=service_url)
# %%
response = discovery.list_projects().get_result()
print(response)
# %%
projects = response['projects']
for project in projects:
print(project)
# %%
name = 'PROJECT_NAME'
projects = [project for project in projects if project['name'] == name]
print(projects)
# %%
project = projects[0]
print(project)
# %%
response = discovery.list_collections(project_id=project['project_id']).get_result()
print(response)
# %%
collections = response['collections']
for collection in collections:
print(collection)
# %%
name = 'COLLECTION_NAME'
collections = [collection for collection in collections if collection['name'] == name]
for collection in collections:
print(collection)
# %%
if len(collections) == 0:
response = discovery.create_collection(project_id=project['project_id'], name='test', language='en').get_result()
print(response)
# %%
print(json.dumps(response, ensure_ascii=False, indent=4))
# %%
#response = discovery.update_collection(project_id=project['project_id'], collection_id='87025aee-6019-f8b6-0000-0192efdda89a', enrichments=[{'enrichment_id': '701db916-fc83-57ab-0000-000000000002', 'fields': ['English Claims']}]).get_result()
#print(response)
# %%
#print(json.dumps(response, indent=4, ensure_ascii=False))
# %%
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme