Example #1
0
 def __init__(self, mountpoint, uri=None, *args, **kw):
     fuse.Fuse.__init__(self, *args, **kw)
     self.fuse_args.mountpoint = mountpoint
     if uri is not None:
         self.server = Server(uri)
     else:
         self.server = Server()
Example #2
0
    def __init__(self, url=None, db='crafts'):
        if url is None:
            s = Server()
        else:
            s = Server(url)

        self.collection = MetricCollection(s['crafts'], 'arts')
Example #3
0
 def __init__(self, convoy_conf):
     LOGGER.info('Init Convoy...')
     self.convoy_conf = convoy_conf
     self.stop_transmitting = False
     self.transmitter_timeout = self.convoy_conf.get(
         'transmitter_timeout', 10)
     self.documents_transfer_queue = Queue()
     self.timeout = self.convoy_conf.get('timeout', 10)
     self.api_client = APIClient(**self.convoy_conf['cdb'])
     self.lots_client = LotsClient(**self.convoy_conf['lots_db'])
     self.assets_client = AssetsClient(**self.convoy_conf['assets_db'])
     user = self.convoy_conf['couchdb'].get('user', '')
     password = self.convoy_conf['couchdb'].get('password', '')
     if user and password:
         self.db = Server(
             "http://{user}:{password}@{host}:{port}".format(
                 **self.convoy_conf['couchdb']),
             session=Session(
                 retry_delays=range(10)))[self.convoy_conf['couchdb']['db']]
     else:
         self.db = Server(
             "http://{host}:{port}".format(**self.convoy_conf['couchdb']),
             session=Session(
                 retry_delays=range(10)))[self.convoy_conf['couchdb']['db']]
     push_filter_doc(self.db)
     LOGGER.info('Added filters doc to db.')
Example #4
0
 def __init__(self, convoy_conf):
     LOGGER.info('Init Convoy...')
     self.convoy_conf = convoy_conf
     self.stop_transmitting = False
     self.transmitter_timeout = self.convoy_conf.get('transmitter_timeout',
                                                     10)
     self.documents_transfer_queue = Queue()
     self.timeout = self.convoy_conf.get('timeout', 10)
     self.api_client = APIClient(**self.convoy_conf['cdb'])
     self.lots_client = LotsClient(**self.convoy_conf['lots_db'])
     self.assets_client = AssetsClient(**self.convoy_conf['assets_db'])
     self.keys = ['classification', 'additionalClassifications', 'address',
             'unit', 'quantity', 'location', 'id']
     self.document_keys = ['hash', 'description', 'title', 'url', 'format',
                      'documentType']
     user = self.convoy_conf['couchdb'].get('user', '')
     password = self.convoy_conf['couchdb'].get('password', '')
     if user and password:
         server = Server(
             "http://{user}:{password}@{host}:{port}".format(
                 **self.convoy_conf['couchdb']),
             session=Session(retry_delays=range(10)))
         self.db = server[self.convoy_conf['couchdb']['db']] if \
             self.convoy_conf['couchdb']['db'] in server else \
             server.create(self.convoy_conf['couchdb']['db'])
     else:
         server = Server(
             "http://{host}:{port}".format(
                 **self.convoy_conf['couchdb']),
             session=Session(retry_delays=range(10)))
         self.db = server[self.convoy_conf['couchdb']['db']] if \
             self.convoy_conf['couchdb']['db'] in server else \
             server.create(self.convoy_conf['couchdb']['db'])
     push_filter_doc(self.db)
     LOGGER.info('Added filters doc to db.')
Example #5
0
def main(couchdb_url=None,
         couchdb_db='openprocurement',
         seq_file=None,
         dump_dir=None):
    if JournalHandler:
        params = {
            'TAGS': 'python,concord',
        }
        LOGGER.addHandler(JournalHandler(**params))
    if couchdb_url:
        server = Server(url=couchdb_url,
                        session=Session(retry_delays=range(10)))
    else:
        server = Server(session=Session(retry_delays=range(10)))
    for i in range(10):
        try:
            db = server[couchdb_db]
        except:
            sleep(i)
        else:
            break
    else:
        db = server[couchdb_db]
    if dump_dir and not os.path.isdir(dump_dir):
        os.mkdir(dump_dir)
    if seq_file and os.path.isfile(seq_file):
        with open(seq_file) as f:
            fdata = f.read()
            last_seq = int(fdata) if fdata.isdigit() else 0
    else:
        last_seq = 0
    seq_block = last_seq / 100
    while True:
        cc = db.changes(timeout=55000,
                        since=last_seq,
                        feed='longpoll',
                        filter='_view',
                        view='conflicts/all',
                        include_docs=True,
                        conflicts=True)
        #wait([
        #spawn(conflicts_resolve, db, c, dump_dir)
        #for c in cc[u'results']
        #])
        for c in cc[u'results']:
            conflicts_resolve(db, c, dump_dir)
        last_seq = cc[u'last_seq']
        if seq_file and seq_block < last_seq / 100:
            with open(seq_file, 'w+') as f:
                f.write(str(last_seq))
            seq_block = last_seq / 100
Example #6
0
    def crearClub(self):
        print("CREAR CLUB")

        serverCDB = Server()
        db = serverCDB['theplacetobet']

        idClub = "1" + str(randint(0, 9)) + str(randint(0, 9)) + str(
            randint(0, 9)) + str(randint(0, 9)) + str(randint(0, 9))

        listaEquipos = []
        cont = 0

        items = []
        for index in range(self.listaEquiposSel.count()):
            items.append(str(self.listaEquiposSel.item(index).text()))
        #Ejemplo de como modificar
        for EquipoSelec in items:
            #EquipoSelec = str(self.listaEquiposSel.item(cont))
            listaEquipos.append(EquipoSelec)
            docEquipo = db.get(EquipoSelec)
            docEquipo["content"]["club"] = idClub
            print(docEquipo)
            db.save(docEquipo)
            cont += 1

        docClub = {'_id': idClub, 'content': {'equipos': listaEquipos}}
        db.save(docClub)

        self.listaEquiposSel.clear()
        self.listaEquiposDisp.clear()
    def test_config_get(self):
        test_config = {
            'main': {
                'resources_api_server':
                'https://lb.api-sandbox.openprocurement.org',
                'resources_api_version': "0",
                'public_resources_api_server':
                'https://lb.api-sandbox.openprocurement.org',
                'couch_url': 'http://localhost:5984',
                'db_name': 'test_db',
                'retrievers_params': {
                    'down_requests_sleep': 5,
                    'up_requests_sleep': 1,
                    'up_wait_sleep': 30,
                    'queue_size': 101
                }
            },
            'version': 1
        }

        bridge = EdgeDataBridge(test_config)
        couch_url_config = bridge.config_get('couch_url')
        self.assertEqual(couch_url_config, test_config['main']['couch_url'])

        del bridge.config['main']['couch_url']
        couch_url_config = bridge.config_get('couch_url')
        self.assertEqual(couch_url_config, None)
        server = Server(test_config['main'].get('couch_url')
                        or 'http://127.0.0.1:5984')
        del server[test_config['main']['db_name']]

        del bridge.config['main']
        with self.assertRaises(DataBridgeConfigError):
            bridge.config_get('couch_url')
 def __init__(self, config):
     super(LogsCollector, self).__init__()
     self.config = config
     self.storage = self.config_get('storage')
     if not self.storage:
         raise LogsCollectorConfigError('Configuration Error: Missing logs'
                                        ' storage.')
     if self.storage == 'couchdb':
         self.couch_url = self.config_get('couch_url')
         self.db_name = self.config_get('log_db')
         if not self.couch_url:
             raise LogsCollectorConfigError('Configuration Error: Missing '
                                            'couch_url')
         else:
             couch_url = urlparse(self.couch_url)
             if couch_url.scheme == '' or couch_url.netloc == '':
                 raise LogsCollectorConfigError('Configuration Error:'
                                                'Invalid couch_url')
         if not self.db_name:
             raise LogsCollectorConfigError('ConnectionError: Missing '
                                            'couchdb name')
         server = Server(self.couch_url,
                         session=Session(retry_delays=range(10)),
                         full_commit=False)
         try:
             if self.db_name not in server:
                 self.db = server.create(self.db_name)
             else:
                 self.db = server[self.db_name]
         except error as e:
             logger.error('Database error: {}'.format(e.message))
             raise LogsCollectorConfigError(e.message)
    def __init__(self,
                 user='******',
                 password='******',
                 url='http://127.0.0.1:5984',
                 db_name='py2store',
                 key_fields=('_id', ),
                 couchdb_client_kwargs=None):
        if couchdb_client_kwargs is None:
            couchdb_client_kwargs = {}
        if user and password:
            # put credentials in url if provided like https://username:[email protected]:5984/
            if '//' in url:  # if scheme present
                url = f'{url.split("//")[0]}//{user}:{password}@{url.split("//")[1]}'
            else:
                url = f'http//{user}:{password}@{url}'
        self._couchdb_server = Server(url=url, **couchdb_client_kwargs)
        self._db_name = db_name
        # if db not created
        if db_name not in self._couchdb_server:
            self._couchdb_server.create(db_name)
        self._cdb = self._couchdb_server[db_name]
        if isinstance(key_fields, str):
            key_fields = (key_fields, )

        self._key_fields = key_fields
Example #10
0
 def test_start(self):
     service = self._start_service()
     couch = Server("http://%s:%d" % (service.host, service.port))
     database = couch.create("test-database")
     posted = {"this": "value"}
     identifier, revision = database.save(posted)
     self.assertEqual(posted, database[identifier])
    def _prepare_couchdb(self):
        server = Server(self.couch_url,
                        session=Session(retry_delays=range(10)))
        try:
            if self.db_name not in server:
                self.db = server.create(self.db_name)
            else:
                self.db = server[self.db_name]
        except Exception as e:
            LOGGER.error('Database error: {}'.format(repr(e)))
            raise

        by_date_modified_view = ViewDefinition(
            self.resource, 'by_dateModified', '''function(doc) {
        if (doc.doc_type == '%(resource)s') {
            var fields=['%(doc_type)sID'], data={};
            for (var i in fields) {
                if (doc[fields[i]]) {
                    data[fields[i]] = doc[fields[i]]
                }
            }
            emit(doc.dateModified, data);
        }}''' % dict(resource=self.resource[:-1].title(),
                    doc_type=self.resource[:-1])
        )
        by_date_modified_view.sync(self.db)

        validate_doc = self.db.get(VALIDATE_BULK_DOCS_ID,
                                   {'_id': VALIDATE_BULK_DOCS_ID})
        if validate_doc.get('validate_doc_update') != VALIDATE_BULK_DOCS_UPDATE:
            validate_doc['validate_doc_update'] = VALIDATE_BULK_DOCS_UPDATE
            self.db.save(validate_doc)
            LOGGER.info('Validate document update view saved.')
        else:
            LOGGER.info('Validate document update view already exist.')
Example #12
0
def main(global_config, **settings):
    config = Configurator(settings=settings)
    config.set_authentication_policy(AuthenticationPolicy(None))
    config.set_authorization_policy(AuthorizationPolicy())
    config.add_renderer('prettyjson', JSON(indent=4))
    config.add_renderer('jsonp', JSONP(param_name='opt_jsonp'))
    config.add_renderer('prettyjsonp', JSONP(indent=4, param_name='opt_jsonp'))
    config.add_subscriber(set_renderer, NewRequest)
    config.include("cornice")
    config.route_prefix = '/api/{}'.format(VERSION)
    config.scan("openprocurement.api.views")

    # CouchDB connection
    server = Server(settings.get('couchdb.url'))
    config.registry.couchdb_server = server
    db_name = os.environ.get('DB_NAME', settings['couchdb.db_name'])
    if db_name not in server:
        server.create(db_name)
    config.registry.db = server[db_name]

    # sync couchdb views
    sync_design(config.registry.db)

    # migrate data
    migrate_data(config.registry.db)

    # S3 connection
    if 'aws.access_key' in settings and 'aws.secret_key' in settings and 'aws.bucket' in settings:
        connection = S3Connection(settings['aws.access_key'], settings['aws.secret_key'])
        config.registry.s3_connection = connection
        bucket_name = settings['aws.bucket']
        if bucket_name not in [b.name for b in connection.get_all_buckets()]:
            connection.create_bucket(bucket_name, location=Location.EU)
        config.registry.bucket_name = bucket_name
    return config.make_wsgi_app()
Example #13
0
 def adduser(self, user, pw):
     db = Server("http://localhost:8888/")['unit_tasks']
     try:
         User(_id=user, password=self.hash(pw)).store(db)
         return "added user"
     except ResourceConflict:
         return "user already exists"
Example #14
0
    def calcularBioritmos(self, jKey):

        #Este metodo calcula el bioritmo para un EQUIPO
        #Calcula el bioritmo para cada jugador individual, los suma y saca la media ponderada
        #Luego, saca la media de los 3 bioritmos (fis, emo, int)

        print("CALCULAR BIORITMOS")
        serverCDB = Server()
        db = serverCDB['theplacetobet']
        docJ = db[jKey]
        pesoAct = float(docJ["content"]["peso"])
        #print("pesoAct: "+str(pesoAct))
        nacJ = docJ["content"]["fechaN"]
        fechaN = datetime.datetime.strptime(nacJ, '%d/%m/%Y')
        fechaAct = datetime.date.today().strftime("%d/%m/%Y")
        fechaAct = datetime.datetime.strptime(fechaAct, '%d/%m/%Y')
        delta = fechaAct - fechaN
        #fisico = (100*math.sin((math.pi*2*delta.days)/23))*pesoAct
        acumFisico = (100 * math.sin(
            (math.pi * 2 * delta.days) / 23)) * pesoAct
        #print("acumFisico: "+str(acumFisico))
        #emocional = (100*math.sin((math.pi*2*delta.days)/28))*pesoAct
        acumEmo = (100 * math.sin((math.pi * 2 * delta.days) / 28)) * pesoAct
        #print("acumEmo: "+str(acumEmo))
        #intelectual = (100*math.sin((math.pi*2*delta.days)/33))*pesoAct
        acumIntel = (100 * math.sin((math.pi * 2 * delta.days) / 33)) * pesoAct
        #print("acumIntel: "+str(acumIntel))
        mediaP = (acumFisico + acumEmo + acumIntel) / (3 * pesoAct)
        #print("mediaP: "+str(mediaP))
        return mediaP
Example #15
0
 def cargarComboJornada(self):
     #print("HOLAAAAAAAAAAA")
     self.comboBox_2.clear()
     serverCDB = Server()
     db = serverCDB["theplacetobet"]
     temporadas = db.view("queries/getPartidas")
     itemActual = str(self.comboBox.currentText())
     listaJornadas = []
     for temporada in temporadas:
         docTemp = temporada.value
         idT = docTemp["_id"]
         listaTempo = idT.split("-")
         idT = listaTempo[0]
         #print(idT)
         #print(itemActual)
         if itemActual == idT:
             #print("*******")
             #print(listaTempo[1])
             if listaTempo[1] not in listaJornadas:
                 listaJornadas.append(listaTempo[1])
     listHols = []
     for i in range(0, len(listaJornadas)):
         x = int(listaJornadas[i])
         listHols.append(x)
     listHols.sort()
     listaJornadas.clear()
     for i in range(0, len(listHols)):
         x = str(listHols[i])
         listaJornadas.append(x)
     self.comboBox_2.addItems(listaJornadas)
Example #16
0
def run(raw_url, db_name, config_doc):
    db = Server(raw_url)[db_name]
    config = db.get(config_doc)

    if 'logger' in config:
        log_stream = db.get_attachment(config_doc, config['logger'])
        logging_conf = tempfile.NamedTemporaryFile(delete=False)
        logging_conf.write(log_stream.read())
        logging_conf.close()
        logging.config.fileConfig(logging_conf.name)
        os.unlink(logging_conf.name)

    def get_component(name):
        components = name.split('.')
        mod = __import__('.'.join(components[:-1]))
        for comp in components[1:]:
            mod = getattr(mod, comp)
        return mod

    mal_cls = get_component(config['maldriver'])
    predictor_cls = get_component(config['predictor'])
    planner_cls = get_component(config['planner'])
    scaler_cls = get_component(config['scaler'])

    with daemon.DaemonContext():
        pass
Example #17
0
 def getConnection(self, url):
     try:
         newServer = Server(url)
         newServer.resource.head()
         return newServer
     except:
         return "failed"
 def setUp(self):
     user = self.config['main']['couch_url'].get('user', '')
     password = self.config['main']['couch_url'].get('password', '')
     if (user and password):
         self.couch_url = "http://{user}:{password}@{host}:{port}".format(
             **self.config['main']['couch_url'])
     else:
         self.couch_url = "http://{host}:{port}".format(
             **self.config['main']['couch_url'])
     server = Server(self.couch_url)
     if self.config['main']['db_name'] in server:
         self.db = server[self.config['main']['db_name']]
     else:
         self.db = server.create(self.config['main']['db_name'])
     array_path = os.path.dirname(os.path.abspath(__file__)).split('/')
     app_path = ""
     for p in array_path[:-1]:
         app_path += p + '/'
     app_path += 'couch_views'
     # for resource in ('/lots'):
     #     push_views(couchapp_path=app_path + resource,
     #                couch_url=couchdb_url)
     validate_doc = {
         '_id': VALIDATE_BULK_DOCS_ID,
         'validate_doc_update': VALIDATE_BULK_DOCS_UPDATE
     }
     try:
         self.db.save(validate_doc)
     except Exception:
         pass
Example #19
0
def main(bulk_size, up_to, num_threads):
    global timer
    s = Server('http://localhost:5984')
    if 'test' in s:
        del s['test']
    db = s.create('test')

    stats_file = 'bulk-perf-%s-%s-%s.dat' % (bulk_size, up_to, num_threads)
    title_file = stats_file + '.meta'
    f = open(title_file, 'w')
    f.write('Bulk size: %s, num threads: %s' % (bulk_size, num_threads))
    f.close()

    stats_file = open(stats_file, 'w')

    stats_lock = Lock()
    exit_event = Event()

    chunks = Queue.Queue()

    def process_chunks():
        global count, timer, internal_counter

        s = Server('http://localhost:5984')
        db = s['test']

        while not exit_event.isSet():
            try:
                chunk = list(chunks.get(timeout=5))
                chunks.task_done()

                db.update(chunk)

                stats_lock.acquire()
                try:
                    count += bulk_size
                    internal_counter += bulk_size

                    if internal_counter >= max(num_threads * bulk_size,
                                               up_to / 1000):
                        end = time()

                        stats_file.write(
                            '%s %s\n' %
                            (count, internal_counter / float(end - timer)))
                        stats_file.flush()

                        timer = end
                        internal_counter = 0
                        print '%.1f%%' % (float(count) / up_to * 100)
                finally:
                    stats_lock.release()

            except Queue.Empty:
                pass

            except Exception, e:
                print 'Exception: %r' % (e, )
                chunks.put(chunk)
                sleep(1)
Example #20
0
 def test_collector_init(self):
     test_config = {}
     with self.assertRaises(LogsCollectorConfigError):
         LogsCollector(test_config)
     test_config = {'main': {}}
     with self.assertRaises(LogsCollectorConfigError):
         LogsCollector(test_config)
     test_config['main'] = {
         'storage': 'couchdb'
     }
     with self.assertRaises(LogsCollectorConfigError):
         LogsCollector(test_config)
     test_config['main']['couch_url'] = 'labuda'
     with self.assertRaises(LogsCollectorConfigError):
         LogsCollector(test_config)
     test_config['main']['couch_url'] = 'http://127.0.0.1:5984'
     with self.assertRaises(LogsCollectorConfigError):
         LogsCollector(test_config)
     test_config['main']['log_db'] = 'test_db'
     try:
         server = Server(test_config['main']['couch_url'])
         del server[test_config['main']['log_db']]
     except ResourceNotFound:
         pass
     with patch('openprocurement.edge.collector.Server.create') as mock_create:
         mock_create.side_effect = error('test error')
         with self.assertRaises(LogsCollectorConfigError):
             LogsCollector(test_config)
Example #21
0
    def setup_backend(self):
        from couchdb import Server

        uri = self.options.pop('uri', u(''))
        couch = Server(uri)
        db_name = self.options.pop('db')
        self.database = couch[db_name]
 def tearDown(self):
     self.config['resources_api_server'] = \
         'https://lb.api-sandbox.openprocurement.org'
     self.config['resources_api_version'] = "0"
     self.config['public_resources_api_server'] = \
         'https://lb.api-sandbox.openprocurement.org'
     self.config['couch_url'] = 'http://localhost:5984'
     self.config['db_name'] = 'test_db'
     self.config['queue_size'] = 101
     self.config['api_clients_count'] = 3
     self.config['workers_count'] = 3
     self.config['retry_workers_count'] = 2
     self.config['filter_workers_count'] = 1
     self.config['retry_workers_count'] = 2
     self.config['retry_default_timeout'] = 5
     self.config['worker_sleep'] = 0.1
     self.config['watch_interval'] = 0.5
     self.config['queue_timeout'] = 0.1
     self.config['resource_items_queue_size'] = -1
     self.config['retry_resource_items_queue_size'] = -1
     self.config['bulk_query_limit'] = 1
     self.config['bulk_query_interval'] = 0.5
     try:
         server = Server(self.config['main'].get('couch_url') or
                         'http://127.0.0.1:5984')
         del server[self.config['main']['db_name']]
     except:
         pass
Example #23
0
def getResults(test=False):
    '''Run a Mango query to get the data'''
    ts = datetime.utcnow().isoformat()[:19]
    payload = {
        "selector": {
            "start_date.timestamp": {
                "$lt": ts
            },
            "status.status_qualifier": "Success",
            "activity_type": "Environment_Observation",
            "subject.name": "Air",
            "subject.attribute.name": "Humidity"
        },
        "fields": ["start_date.timestamp", "subject.attribute.value"],
        "sort": [{
            "start_date.timestamp": "desc"
        }],
        "limit": 250
    }
    db_name = 'mvp_data'
    if test:
        print(payload)
    server = Server()
    db = server[db_name]
    return db.find(payload)
Example #24
0
    def recuperarPersona(self):
        print('Entro al metodo')
        fechaN = self.fecha_nacimiento.date()
        fechaN = fechaN.toPyDate()
        identidad = self.numero_dentidad.text()
        pNombre = self.primer_nombre.text()
        pApellido = self.primer_apellido.text()
        rol = str(self.combo_box_desempeno.currentText())
        peso = self.doubleSpinBox.value()
        print(fechaN)
        print(identidad)
        print(pNombre)
        print(pApellido)
        print(rol)
        print(peso)

        serverCDB = Server()
        db = serverCDB['theplacetobet']

        if identidad not in db:
            docPersona = {
                '_id': identidad,
                'content': {
                    'nombre': pNombre,
                    'apellido': pApellido,
                    'fechaN': fechaN.strftime('%m/%d/%Y'),
                    'rol': rol,
                    'peso': peso,
                    'equipo': "N/A"
                }
            }
            db.save(docPersona)
        else:
            print("Ya existe una persona con ese ID")
Example #25
0
    def simulacionPartido(self):
        acumLocal = 0
        acumVisita = 0
        for i in range(0, 10):
            item1 = self.tableWidget_3.item(i, 1)
            item2 = self.tableWidget_4.item(i, 1)
            acumLocal += float(item1.text())
            acumVisita += float(item2.text())
        mediaLocal = acumLocal / 11
        mediaVisita = acumVisita / 11
        golesLocal = int(round(mediaLocal / 5))
        if golesLocal < 0:
            golesLocal = 0
        print("Local: " + str(golesLocal))
        golesVisita = int(round(mediaVisita / 5))
        if golesVisita < 0:
            golesVisita = 0
        print("Visita: " + str(golesVisita))
        self.label_54.setText(str(golesLocal))
        self.label_56.setText(str(golesVisita))
        jugado = float(self.labelMoney.text())
        apuesta = float(self.labelMoney.text())
        if (golesLocal > golesVisita and self.radioButton.isChecked()) or (
                golesLocal < golesVisita and self.radioButton_3.isChecked()
        ) or (golesLocal == golesVisita and self.radioButton_2.isChecked()):
            apuesta *= 1.5
            self.labelMoney.setText(str(apuesta))
        elif (golesLocal <= golesVisita and self.radioButton.isChecked()) or (
                golesLocal >= golesVisita and self.radioButton_3.isChecked()
        ) or (golesLocal != golesVisita and self.radioButton_3.isChecked()):
            apuesta *= 0.75
            self.labelMoney.setText(str(apuesta))
        else:
            self.labelMoney.setText(str(apuesta))

        #Insertar la apuesta en la base de datos
        idT = str(self.comboBox.currentText())
        idJ = str(self.comboBox_2.currentText())
        idE = str(self.comboBox_3.currentText())
        myKey = "A-" + idT + "-" + idJ + "-" + idE

        serverCDB = Server()
        db = serverCDB["theplacetobet"]

        part = db.get(idT + "-" + idJ + "-" + idE)
        part["content"]["score_local"] = golesLocal
        part["content"]["score_visita"] = golesVisita
        db.save(part)

        docApuesta = {
            "_id": myKey,
            "content": {
                "jugado": jugado,
                "ganado": apuesta,
                "golesLocal": golesLocal,
                "golesVisita": golesVisita
            }
        }
        db.save(docApuesta)
Example #26
0
 def isuserp(self, user, pw):
     db = Server("http://localhost:8888/")['unit_tasks']
     if len(
             list(
                 db.view('_design/users/isvalid',
                         key=[user, self.hash(pw)]))) == 1:
         return "1"
     return "0"
Example #27
0
 def setUp(self):
     self.couch_url = 'http://127.0.0.1:5984'
     self.db_name = 'test_db'
     try:
         server = Server(self.couch_url)
         del server[self.db_name]
     except:
         pass
Example #28
0
def getResults():
#    header={"Content-Type":"application/json"}
    ts = datetime.utcnow().isoformat()[:19]
    payload={"selector":{"start_date.timestamp":{"$lt":ts},"status.status_qualifier":{"$eq": "Success"}, "activity_type":{"$eq":"Environment_Observation"}, "subject.name":{"$eq": "Air"}, "$or":[{"subject.attribute.name":"Humidity"}, {"subject.attribute.name":"Temperature"}]}, "fields":["start_date.timestamp", "subject.attribute.name", "subject.attribute.value"], "sort":[{"start_date.timestamp":"desc"}], "limit":250}        
    server = Server()
    db_name = 'mvp_data'
    db = server[db_name]
    return db.find(payload)
 def __init__(self, config):
     """
     Check CouchDB availability and set _db attribute
     """
     server, db = config.get("COUCH_DATABASE").rsplit('/', 1)
     server = Server(server, session=Session(retry_delays=range(10)))
     database = server[db] if db in server else server.create(db)
     self._db = database
Example #30
0
def get_Doc(docname, view='_all_docs'):
    #https://www.openshift.com/forums/openshift/permission-denied-on-port-8081
    #SERVER = Server('http://194.29.175.241:5984/')
    SERVER = Server(COUCHDB_HOST)
    if docname in SERVER:
        doc = SERVER[docname].view(view)
        return doc
    return None