Example #1
0
 def init_app(self, app):
     self.client = Cloudant.iam(app.config.get("CLOUDANT_USER"),
                                app.config.get("CLOUDANT_APIKEY"),
                                connect=True)
     self.db = self.client.create_database(self.db_name,
                                           throw_on_exists=False)
     logging.info("Connection to Cloudant successful")
Example #2
0
 def __init__(self):
     super().__init__()
     self.charset = 'gbk'
     self.base_url = 'http://t66y.com'
     self.page_url = 'thread0806.php?fid=7&search=today'
     self.client = Cloudant.iam(os.environ.get('db_user'),
                                os.environ.get('db_key'),
                                connect=True)
     self.db = self.client[os.environ.get('db_name', 'serverless')]
     self.reply_id = 'pending_reply_list'
     self.day = self.utc_dt.strftime('%Y-%m-%d')
def Setup() -> database.CouchDatabase:
    """Creates and returns DB"""
    if 'VCAP_SERVICES' in os.environ:
        vcap = json.loads(os.getenv('VCAP_SERVICES'))
        print('Found VCAP_SERVICES')
        if 'cloudantNoSQLDB' in vcap:
            creds = vcap['cloudantNoSQLDB'][0]['credentials']
            user = creds['username']
            # password = creds['password']
            url = 'https://' + creds['host']

            apiKey = creds['apikey']
            # client = cloudant_iam(user, apiKey, url=url, connect=True)
            client = Cloudant.iam(user, apiKey, url=url, connect=True)
            db = client.create_database(db_name, throw_on_exists=False)
    elif "CLOUDANT_URL" in os.environ:
        client = Cloudant.iam(os.environ['CLOUDANT_USERNAME'],
                              os.environ['CLOUDANT_PASSWORD'],
                              url=os.environ['CLOUDANT_URL'],
                              connect=True)
        db = client.create_database(db_name, throw_on_exists=False)
    elif os.path.isfile('vcap-local.template.json'):
        with open('vcap-local.template.json') as f:
            vcap = json.load(f)
            print('Found local VCAP_SERVICES')
            creds = vcap['services']['cloudantNoSQLDB'][0]['credentials']
            user = creds['username']
            # password = creds['password']

            apiKey = creds['apikey']
            url = 'https://' + creds['host']
            # client = Cloudant(user, apiKey, url=url, connect=True)
            client = Cloudant.iam(user, apiKey, url=url, connect=True)
            db = client.create_database(db_name, throw_on_exists=False)

    else:
        print("no db found")

    return db
Example #4
0
    def run(self, **kwargs):
        utc_dt = datetime.utcnow().replace(tzinfo=timezone.utc)
        bj_dt = utc_dt.astimezone(timezone(
            timedelta(hours=8))).strftime('%Y-%m-%d %H:%M:%S')

        client = Cloudant.iam(os.environ.get('db_user'),
                              os.environ.get('db_key'),
                              connect=True)
        db = client['db-1']
        for document in db:
            app_data = self.get_ms_token(**document)
            if document['auth_type'] == 'oauth':
                data = self.refresh_token(**document)
                document['access_token'] = data['access_token']
                document['expires_time'] = int(time.time()) + 3500
                document['update_time'] = bj_dt
                if data.get('refresh_token'):
                    document['refresh_token'] = data['refresh_token']
            app_data['expires_time'] = int(time.time()) + 3500
            app_data['update_time'] = bj_dt
            document['app_data'] = app_data
            document.save()
            self.logger.info(f"{document['_id']} refresh done.")
        client.disconnect()
Example #5
0
from cloudant import Cloudant
from cloudant.result import Result
import json

client = Cloudant.iam("e75ee703-7ad3-46f2-91cd-f77a6a0d2094-bluemix",
                      "vb5tLFvKQ_fpWBiSG-5lbKnU2XaMp2VeOryqTXTll7wn")
client.connect()

my_db = client['maindb']

sample_data = [[1, "one two three", "boiling", 100], [2, "two", "hot", 40],
               [3, "three", "warm", 20], [4, "four", "cold", 10],
               [5, "five", "freezing", 0]]

documents_list = []
for document in sample_data:

    number = document[0]
    name = document[1]
    description = document[2]
    temperature = document[3]

    json_document = {
        "numberField": number,
        "nameField": name,
        "descriptionField": description,
        "temperatureField": temperature
    }

    documents_list.append(json_document)
my_db.bulk_docs(documents_list)
Example #6
0
 def __init__(self, options):
     self.my_database = None
     self.orgId = options['orgId']
     self.cloudant_client = Cloudant.iam(options['username'],
                                         options['apikey'],
                                         connect=True)
Example #7
0
 def __init__(self):
     self.one = OneDrive()
     self.client = Cloudant.iam(ACCOUNT_NAME, API_KEY, connect=True)
     self.db = self.client.create_database(DB_NAME)
     self.one_type = None
Example #8
0
import json

app = Flask(__name__, static_url_path='')

db_name = 'mydb'
client = None
db = None

if 'VCAP_SERVICES' in os.environ:
    vcap = json.loads(os.getenv('VCAP_SERVICES'))
    print('Found VCAP_SERVICES')
    if 'cloudantNoSQLDB' in vcap:
        credentials = vcap['cloudantNoSQLDB'][0]['credentials']
        user = credentials['username']
        api_key = credentials['apikey']
        client = Cloudant.iam(user, api_key, connect=True)
        db = client.create_database(db_name, throw_on_exists=False)
elif "CLOUDANT_URL" in os.environ:
    client = Cloudant(os.environ['CLOUDANT_USERNAME'],
                      os.environ['CLOUDANT_PASSWORD'],
                      url=os.environ['CLOUDANT_URL'],
                      connect=True)
    db = client.create_database(db_name, throw_on_exists=False)
elif os.path.isfile('vcap-local.json'):
    with open('vcap-local.json') as f:
        vcap = json.load(f)
        print('Found local VCAP_SERVICES')
        credentials = vcap['services']['cloudantNoSQLDB'][0]['credentials']
        user = credentials['username']
        api_key = credentials['apikey']
        client = Cloudant.iam(user, api_key, connect=True)
Example #9
0
import json
from datetime import datetime
import handle_report_json

# authenticator = IAMAuthenticator(IBM_CLOUDANT_APIKEY)
# client = CloudantV1(authenticator=authenticator)
# client.set_service_url(IBM_CLOUDANT_URL)
# client = CloudantV1.new_instance(service_name="ibm-cloudant")

# database_name = "risk_information"

IBM_CLOUDANT_URL = "https://348014a4-91de-4c56-8d88-eb995b41f568-bluemix.cloudantnosqldb.appdomain.cloud/"
IBM_CLOUDANT_APIKEY = "aR49WSc7QKmx-wm7viiy7Tr8f2NcB-lGrdpsNJmpzfsc"
IBM_CLOUDANT_USERNAME = "******"

client = Cloudant.iam(IBM_CLOUDANT_USERNAME, IBM_CLOUDANT_APIKEY, connect=True)
'''
Format for create
JSON Document={
    "patient_id"         = 12878,
    "function"           = create,
    "patient_risk_level" = low/medium/high,
    "patient_at_risk_of" = DISEASE NAME
}
'''


# def create_patientdoc(patient_id,patient_risk_level,patient_at_risk_of):
def create_patientdoc(jsonDocument, database):
    database = client[database]
    patient_id = jsonDocument['patient_id']