Esempio n. 1
0
    async def get(self):

        status = False
        code = 4000
        result = []
        message = ''

        try:
            fq = self.orgPos.find({
                'profileId': self.profileId,
                # 'formId': ObjectId(self.get_arguments('id')[0])
            })
            async for r in fq:
                result.append(r)

            if len(result):
                status = True
                message = ''
                code = 2000
            else:
                message = 'No data found.'
                code = 3100
            Log.i('Hello')
        except Exception as e:
            status = False
            if not len(message):
                template = 'Exception: {0}. Argument: {1!r}'
                code = 5010
                iMessage = template.format(type(e).__name__, e.args)
                message = 'Internal Error, Please Contact the Support Team.'
                exc_type, exc_obj, exc_tb = sys.exc_info()
                fname = exc_tb.tb_frame.f_code.co_filename
                Log.w('EXC', iMessage)
                Log.d(
                    'EX2', 'FILE: ' + str(fname) + ' LINE: ' +
                    str(exc_tb.tb_lineno) + ' TYPE: ' + str(exc_type))
        response = {'code': code, 'status': status, 'message': message}
        Log.d('RSP', response)
        try:
            response['result'] = result
            response = json.loads(bdumps(response))
            self.write(response)
            await self.finish()
            return
        except Exception as e:
            status = False
            template = 'Exception: {0}. Argument: {1!r}'
            code = 5011
            iMessage = template.format(type(e).__name__, e.args)
            message = 'Internal Error, Please Contact the Support Team.'
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = exc_tb.tb_frame.f_code.co_filename
            Log.w('EXC', iMessage)
            Log.d(
                'EX2', 'FILE: ' + str(fname) + ' LINE: ' +
                str(exc_tb.tb_lineno) + ' TYPE: ' + str(exc_type))
            response = {'code': code, 'status': status, 'message': message}
            self.write(response)
            await self.finish()
            return
Esempio n. 2
0
def usuario_c():
    if request.method == 'GET':
        return jsonify([json.loads(bdumps(u)) for u in db.usuarios.find()])
    else:
        usuario = request.get_json()
        if 'nome' not in usuario.keys() or not usuario['nome'].strip():
            return make_response(jsonify({'message' : 'Propriedade nome Obrigadotória'}), 400) 
        db.usuario.insert(usuario))
        return jsonify({'message : Usuario cadastrado com sucesso'})
Esempio n. 3
0
def list(event, context):
    """
    List the entries in the guestbook. 
    """
    try:
        client = pymongo.MongoClient("mongodb://{}".format(MONGODB_HOST),
                                     int(MONGODB_PORT))
        collection = client[MONGODB_NAME][MONGODB_COLLECTION]
        entries = [x for x in collection.find({})]
        result = bdumps({"entries": entries})
        return result
    except pymongo.errors.PyMongoError as err:
        return resp(json.dumps({"error": "MongoDB error : " + str(err)}), 500)
    except Exception as err:
        return resp(json.dumps({"error": str(err)}), 500)
Esempio n. 4
0
def list(event, context):
    """
    List the photos with their meta data
    """
    try:
        minio, mongo = setup()
    except Exception as err:
        return json.dumps({"setup error": str(err)})

    try:
        collection = mongo[mgo_database][MONGODB_COLLECTION]
        photos = [x for x in collection.find({})]
        result = bdumps({"photos": photos})
        return result
    except Exception as err:
        return json.dumps({"error": str(err)})
Esempio n. 5
0
def usuarios():
    if request.method == 'GET':
        return jsonify([json.loads(bdumps(u)) for u in db.usuarios.find()])
    else:
        usuario = request.get_json()
        keys = usuario.keys()
        for k in ('nome','email'):
            if k not in keys or not usuario[k].strip():
                return make_response(jsonify({'message': 'propriedade {0} obrigatória..'.format(k)}),400)

        # if 'nome' not in usuario.keys() or not usuario['nome'].strip():
        #     return make_response(jsonify({'message' : 'propriedade nome obrigatória '}), 400)
        # if 'email' not in usuario.keys() or not usuario['email'].strip():
        #     return make_response(jsonify({'message' : 'propriedade email obrigatória '}), 400)  


        db.usuarios.insert(usuario)
        return jsonify({'message' : 'usuario cadastrado com sucesso'})
Esempio n. 6
0
    async def post(self):

        status = False
        code = 4000
        result = []
        message = ''

        try:
            try:
                # CONVERTS BODY INTO JSON
                self.request.arguments = bloads(self.request.body.decode())
            except Exception as e:
                code = 4100
                message = 'Expected Request Type JSON.'
                raise Exception

            self.request.arguments['profileId'] = self.profileId
            rs = await self.orgPos.insert_one(self.request.arguments)
            status = True
            code = 2000
            message = 'Organization position structure has been created.'
            result = [rs.inserted_id]

        except Exception as e:
            status = False
            # self.set_status(400)
            if not len(message):
                template = 'Exception: {0}. Argument: {1!r}'
                code = 5010
                iMessage = template.format(type(e).__name__, e.args)
                message = 'Internal Error, Please Contact the Support Team.'
                exc_type, exc_obj, exc_tb = sys.exc_info()
                fname = exc_tb.tb_frame.f_code.co_filename
                Log.w('EXC', iMessage)
                Log.d(
                    'EX2', 'FILE: ' + str(fname) + ' LINE: ' +
                    str(exc_tb.tb_lineno) + ' TYPE: ' + str(exc_type))
        response = {'code': code, 'status': status, 'message': message}
        Log.d('RSP', response)
        try:
            response['result'] = result
            response = json.loads(bdumps(response))
            self.write(response)
            await self.finish()
            return
        except Exception as e:
            status = False
            template = 'Exception: {0}. Argument: {1!r}'
            code = 5011
            iMessage = template.format(type(e).__name__, e.args)
            message = 'Internal Error, Please Contact the Support Team.'
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = exc_tb.tb_frame.f_code.co_filename
            Log.w('EXC', iMessage)
            Log.d(
                'EX2', 'FILE: ' + str(fname) + ' LINE: ' +
                str(exc_tb.tb_lineno) + ' TYPE: ' + str(exc_type))
            response = {'code': code, 'status': status, 'message': message}
            self.write(response)
            await self.finish()
            return
Esempio n. 7
0
def get_images():
    mongo, minio = setup()
    collection = mongo["photos"]["entries"]
    photos = [x for x in collection.find({})]
    result = bdumps({"photos": photos})
    return result, 200
Esempio n. 8
0
def apiOperations():
    col = mdb['operations']
    l = col.find({'date': {'$gte': dt.now(None) - td(2)}}).sort("date", 1)
    res = list(d for d in l)
    return bdumps(dict(data=res, success=True))
Esempio n. 9
0
def usr_banco():
    return jsonify([json.loads(bdumps(u)) for u in db.usuarios.find()])
Esempio n. 10
0
def teste():
    usuarios = []
    for x in db.usuarios.find():
        usuarios.append(json.loads(bdumps(x)))
    return jsonify(usuarios)
Esempio n. 11
0
        }
    }

    @staticmethod
    def deleteFolder(path){
        if os.path.exists(path){
            shutil.rmtree(path)
        }else{
            Utils.LOGGER.warn('The folder {} does not exist.'.format(path))
        }
    }

    @staticmethod
    def saveJson(path,data,pretty=True,use_bson=False){
        if use_bson{
            Utils.saveFile(path,bdumps(data))
            return
        }
        with open(path, 'w') as fp{
            json.dump(data, fp, indent=3 if pretty else None)
        }
    }

    @staticmethod
    def changeStrDateFormat(date,input_format,output_format){
        date=datetime.strptime(date, input_format)
        return date.strftime(output_format)
    }

    @staticmethod
    def loadJson(path,use_bson=False){