# %%
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]
for project in projects:
print(project)
# %%
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:
for collection in collections:
response = discovery.get_collection(project_id=project['project_id'], collection_id=collection['collection_id']).get_result()
print(response)
print(json.dumps(response, ensure_ascii=False, indent=4))
# %%
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