Skip to content

Instantly share code, notes, and snippets.

@remkohdev
Last active October 11, 2016 23:37
Show Gist options
  • Save remkohdev/5bad6f2a34ed3dcd0e82012bb9d873a1 to your computer and use it in GitHub Desktop.
Save remkohdev/5bad6f2a34ed3dcd0e82012bb9d873a1 to your computer and use it in GitHub Desktop.
from cloudant.client import Cloudant
import json
username = "<cloudant_username>"
password = "<cloudant_password>"
cloudantURL = "<cloudant_url>"
client = Cloudant(username, password, url=cloudantURL)
def SaveNews(doc):
print('Save Document')
# class should be 'dict'
if isinstance(doc, str):
doc = json.loads(doc)
client.connect()
my_database = client['newssentiment']
my_document = my_database.create_document(doc)
if my_document.exists():
print('Save Document: SUCCESS')
else:
print('Save Document: ERROR')
client.disconnect()
def GetNews():
client.connect()
my_database = client['newssentiment']
# document_id
news = my_database[document_id]
client.disconnect()
# json to string
news = json.dumps(news)
return news;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment