-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster_point.py
45 lines (39 loc) · 1.23 KB
/
cluster_point.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import pycps
import json
class CPDatabase(object):
# Create a connection to a Clusterpoint database.
def __init__(self):
DB_NAME = 'apollo'
CLIENT_EMAIL = '[email protected]'
CLIENT_PASSWORD = 'upxf3250lsr'
ACCOUNT_ID = '100908'
self.con = pycps.Connection('tcp://cloud-us-0.clusterpoint.com:9007', DB_NAME, CLIENT_EMAIL, CLIENT_PASSWORD, ACCOUNT_ID)
def insert_mixed(self, docs_mixed):
#docs_mixed = {1: {'text': 'Lorem ipsum.', 'textxxx': 'Lorem ipsum.', 'title': 'Title!'}, 2: '<document/>'}
try:
self.con.insert(docs_mixed)
except pycps.APIError as e:
print(e)
def insert(self, obj):
print("inserting...")
try:
self.con.insert(obj)
except pycps.APIError as e:
print(e)
def retrieve(self, id):
try:
response = self.con.retrieve(id)
if response.get_documents:
for id, document in response.get_documents().items():
return document
except pycps.APIError as e:
print(e)
if e.code == 2824:
print("Requested non-existing id(s): {0}".format(', '.join(e.document_id)))
# def update_sentiment(self, ingredient, sentiment)
# # Update.
# doc['text'] = 'Changed'
# try:
# con.update({ingredient: doc})
# except pycps.APIError as e:
# print(e)