Last active
February 6, 2019 21:34
-
-
Save bparrill/b892d236bf3ddf72a5a8413f1761ce65 to your computer and use it in GitHub Desktop.
Clear all Discovery Content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from watson_developer_cloud import DiscoveryV1 | |
discoveryCredF = 'DiscoveryCreds.json' | |
collection_id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' | |
configuration_id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' | |
environment_id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' | |
def getCreds(fn): | |
with open(fn, 'r') as cred_file: | |
creds = json.load(cred_file) | |
return creds | |
def discoveryConnect(f): | |
discoveryCreds = getCreds(f) | |
discovery = DiscoveryV1( | |
version='2018-12-03', | |
iam_apikey=discoveryCreds.get('apikey'), | |
url=discoveryCreds.get('url')) | |
return discovery | |
discovery = discoveryConnect(discoveryCredF) | |
all_docs = discovery.query(environment_id, collection_id, query='answer:*').get_result() | |
i = 0 | |
for doc in all_docs.get('results'): | |
print('Deleting', doc.get('id'), '...') | |
discovery.delete_document(environment_id, collection_id, doc.get('id')) | |
i += 1 | |
print(f'{i} documents deleted.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment