Last active
October 11, 2016 23:37
-
-
Save remkohdev/5bad6f2a34ed3dcd0e82012bb9d873a1 to your computer and use it in GitHub Desktop.
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
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