# %%
from ibm_watson import DiscoveryV2
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
# %%
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 response['projects'] if project['name'] == name]
for project in projects:
print(project)
# %%
project = projects[0]
response = discovery.list_collections(project_id=project['project_id']).get_result()
print(response)
# %%
collections = response['collections']
for collection in collections:
print(collection)
# %%
collection = collections[0]
response = discovery.get_collection(project_id=project['project_id'], collection_id=collection['collection_id']).get_result()
print(response)
# %%
fp = 'CSV FILE PATH'
with open(file=fp, mode='rb') as file:
response = discovery.add_document(
project_id=project['project_id'],
collection_id=collection['collection_id'],
file=file,
file_content_type='text/csv',
).get_result()
print(response)
# %%
とりあえずすげーでかいデータはCUIで登録しておいて、以下を参考にするのが吉な気がしている…
https://qiita.com/nax/items/9037e511c0948eb5a173