def synchronize_location(self, nr_things1, location, user):
        thingsXLocation = ThingsXLocation()
        things = Things()

        thingsExists = things.search_things_by_num1(nr_things1)
        if thingsExists != False:
            pabe_id = thingsExists.code_things
            exists = thingsXLocation.check_thing_location_exists(nr_things1)

            if exists == True:
                update = thingsXLocation.update_thing_location(
                    pabe_id, location, user)
                if update:
                    return True
                else:
                    return 'Ocorreu um erro ao atualizar a localização da coisa'
            elif exists == False:
                insert = thingsXLocation.insert_patr_bens_x_localizacao(
                    pabe_id, location, user)
                if insert:
                    return True
                else:
                    return 'Ocorreu um erro ao inserir a localização da coisa'
            else:
                return 'Ocorreu um erro ao verificar a localização atual da coisa'
        elif thingsExists == False:
            return 'Codigo da coisa inexistente'
        else:
            return 'Ocorreu um erro ao verificar se a coisa existe'
Пример #2
0
def thingsTableWriter():
    things = Things ()
    location = things.search_locations ()

    code = request.form['code1']
    loca_id = request.form['location2']

    if loca_id != "0" and code == "":
        dados = things.search_things_inactives_by_location(loca_id)

        if dados == False:
            msg = "Objects not found."
            return render_template ('/writer.html', locations=location, message=msg)

    elif loca_id == "0" and code != "":
        dados = []
        dados.append(things.search_things_by_num1(code))

        if dados[0] == False:
            msg = "Objects not found."
            return render_template ('/writer.html', locations=location, message=msg)
    else:
        msg = "Please, Enter a Code or Location to Write."
        return render_template ('/writer.html', locations=location, message=msg)

    return render_template('/writer.html', locations=location, dado=dados)
Пример #3
0
def findThing():
    numThing = request.form['numeroPat']

    things = Things()
    try:
        response = things.search_things_by_num1(numThing)

        if response == False:
            return "Nenhuma coisa encontrada com o numero informado"
        else:
            return render_template('/things.html', thing=response)
    except Exception as e:
        return 'Erro no servidor. Contate o analista responsavel!'
Пример #4
0
def search_all_things_actives(token):
    # valida token
    user = User()
    resp = user.verify_token(token)
    if resp == False:
        return jsonify({'response': 'Token Invalido'})
    elif resp == 'ERRO':
        return jsonify({'response': 'Erro ao verificar token'})

    things = Things()
    response = things.search_all_things_actives()
    if response == False:
        return jsonify({'response': 'Nenhum objeto encontrado'})
    elif response == 'ERRO':
        return jsonify({'response': 'Ocorreu um erro no servidor'})
    else:
        return json.dumps(para_dict(response))
Пример #5
0
def tableRead():
    arraySync = request.form.getlist('arraySync')
    location = request.form['arraySyncLoc']
    things = Things()
    arrayThings = []

    for numero in arraySync:
        coisa = things.search_things_by_num2(numero)
        coisa.location_current.loca_id = location
        coisa.location_current.loca_room = things.search_location_by_id(location).loca_room
        arrayThings.append(coisa)


    #abre o json para salvar em uma lista o que ja esta gravado
    with open('sync.json') as json_data:
        data = json.load(json_data)
        list = []
        for thing in data['Things']:
            list.append(thing) #lista com os arquivos do json

    texto = None
    arq = open('sync.json', 'w')
    inicio = "{\n\n\"Things\":[\n\n";
    arq.write(inicio);


    if (len(list) != 0):
        # insere no novo arquivo os antigos
        for antigo in list:
            text = json.dumps(para_dict(antigo))
            arq.write(text + ",\n")

    tamanho = (len(arrayThings))
    for thing in arrayThings:
        if (tamanho == 1):
            texto = json.dumps(para_dict(thing))
            arq.write(texto)
            tamanho = tamanho - 1
        else:
            texto = json.dumps(para_dict(thing))
            arq.write(texto + ",\n")
            tamanho = tamanho - 1
    arq.write("\n\n]\n}")
    arq.close()
    return render_template('/reader.html', textoSuccess = "Saved Successfully. Please, Synchronize Things !")
Пример #6
0
def writerInTag():
    numero = request.form['radioSelected']

    things = Things ()
    location = things.search_locations ()
    active = things.active_things_by_num1(numero)

    if active == True:
        # yield render_template('writer.html', tagAtiv = 'Aproxime a etiqueta para active')
        tag = start (str(numero))
        # tag = True

        if tag == True:
            things = Things ()
            exits = things.active_things_by_num1(numero)

            if exits == True:
                return render_template ('/writer.html', msg="Tag Activated Successfully !!", locations=location)
            else:
                return render_template ('/writer.html', erro="Tag Activation Error !!", locations=location)

        else:
            return render_template ('/writer.html', erro="Could not Activate Tag. Contact the Analyst!", locations=location)
    else:
        return render_template ('/writer.html', erro="Error Activating Tag in local database !", locations=location)
Пример #7
0
def active_thing_by_num(token, num):
    # valida token
    user = User()
    resp = user.verify_token(token)
    if resp == False:
        return jsonify({'response': 'Token Invalido'})
    elif resp == 'ERRO':
        return jsonify({'response': 'Erro ao verificar token'})

    things = Things()
    exits = things.search_things_by_num1(num)
    if exits:
        response = things.active_things_by_num1(num)
        if response == False:
            return jsonify({'response': 'Ocorreu um erro ao ativar a etiqueta'})
        else:
            return jsonify({'response': 'true'})
    else:
        return jsonify({'response': 'Objeto nao encontrado'})
Пример #8
0
def addthing():
    descricao = request.form['descricao']
    num1 = request.form['num1']
    num2 = request.form['num2']
    preco = request.form['preco']
    situacao = request.form['situacao']
    estado = request.form['estado']
    observacao = request.form['observacao']

    thing = Things()
    try:
        response = thing.insert_new_thing(num1, num2, descricao, preco, situacao, estado, observacao)
        if response == True:
            return "Coisa cadastrada com sucesso."
        else:
            return "Erro ao cadastrar coisa."

    except Exception as e:
        return 'Erro no servidor. Contate o analista responsavel !!'
Пример #9
0
def editThing():
    id = request.form['id']
    descricao = request.form['descricao']
    num1 = request.form['num1']
    num2 = request.form['num2']
    preco = request.form['preco']
    situacao = request.form['situacao']
    estado = request.form['estado']
    observacao = request.form['observacao']

    thing = Things()

    try:
        response = thing.update_thing2(id, descricao, num1, num2, preco, situacao, estado, observacao)
        if response == True:
            return "Coisa atualizada com sucesso"
        else:
            return "Erro ao atualizar coisa"
    except Exception as e:
        return 'Erro no servidor. Contate o analista responsavel!'
    def synchronize_things(self, nr_things1, situation, state, note, user,
                           current_location):
        things = Things()
        thingsXLocation = ThingsXLocation()

        thingsExists = things.search_things_by_num1(nr_things1)
        if thingsExists != False:
            pabe_id = thingsExists.code_things
            update = things.update_thing(pabe_id, situation, state, note)
            if update == False:
                return 'Ocorreu um erro ao atualizar o objeto'

            if current_location != None and current_location != "0":
                exists = thingsXLocation.check_thing_location_exists(
                    nr_things1)
                if exists == True:
                    current_location_db = thingsXLocation.get_location_current(
                        pabe_id)
                    if current_location != False and current_location != 'ERRO':
                        if current_location_db != current_location:
                            update = thingsXLocation.update_thing_location(
                                pabe_id, current_location, user)
                            if update:
                                return True
                            else:
                                return 'Ocorreu um erro ao atualizar a localização da coisa'

                elif exists == False:
                    insert = thingsXLocation.insert_patr_bens_x_localizacao(
                        pabe_id, current_location, user)
                    if insert:
                        return True
                    else:
                        return 'Ocorreu um erro ao inserir a localização da coisa'
                else:
                    return 'Ocorreu um erro ao verificar a localização atual da coisa'
            return True
        elif thingsExists == False:
            return 'Codigo da coisa inexistente'
        else:
            return 'Ocorreu um erro ao verificar se a coisa existe'
Пример #11
0
def thingsTable():
    things = Things ()
    location = things.search_locations ()

    loca_id = request.form['location']
    status = request.form['status']

    if loca_id == "0" and status == "1":
        thingsdata = things.search_all_things_actives()

        if thingsdata == False:
            msg = "Object not found."
            return render_template ('/things.html', location=location, message=msg)

    elif loca_id == "0" and status == "2":
        thingsdata = things.search_all_things_inactives()

        if thingsdata == False:
            msg = "Object not found."
            return render_template ('/things.html', location=location, message=msg)

    elif loca_id != "0" and status == "0":
        thingsdata = things.search_things_by_location(loca_id)

        if thingsdata == False:
            msg = "Object not found."
            return render_template ('/things.html', location=location, message=msg)

    elif loca_id != "0" and status == "1":
        thingsdata = things.search_things_actives_by_location(loca_id)

        if thingsdata == False:
            msg = "Object not found."
            return render_template ('/things.html', location=location, message=msg)

    elif loca_id != "0" and status == "2":
        thingsdata = things.search_things_inactives_by_location(loca_id)

        if thingsdata == False:
            msg = "Object not found."
            return render_template ('/things.html', location=location, message=msg)

    elif loca_id == "0" and status == "0":
        msg = "Please select a Location or Status for consultation. Or, if you prefer, select both."
        return render_template ('/things.html', location=location, message=msg)

    # thingsData = things.search_things_by_location (loca_id)

    return render_template('/things.html', thingsdata=thingsdata, location=location)
Пример #12
0
def metodoTeste():
    thingsToSync = request.form.getlist('extensions')
    todasCoisas = request.form.getlist('listaDasCoisas')
    thingsSync = ThingsSynchronization()
    things = Things()
    for thing in thingsToSync:
        active = activeThings(session['token'], thing)
        if active == True:
            resp = thingsSync.synchronizationThings(session['token'], request.form['locas'+thing], thing)
        elif active == 0:
            return render_template('/synchronize.html', msgErro="No Thing has been found to synchronize.")
        else:
            return render_template('/synchronize.html', msg="Server Connection Error.")

    if resp == True:
        list3 = []
        thingsObject = Things()
        for numero in todasCoisas:
           if numero not in thingsToSync:
            thing = thingsObject.search_things_by_num2(numero)
            thing.location_current = things.search_location_by_id(request.form['locas'+numero])
            list3.append(thing)


        arq = open('sync.json', 'w')
        inicio = "{\n\n\"Things\":[\n\n";
        arq.write(inicio);

        tamanho = (len(list3))
        for coisa in list3:
            if (tamanho == 1):
                texto = json.dumps(para_dict(coisa))
                arq.write(texto)
                tamanho = tamanho - 1
            else:
                texto = json.dumps(para_dict(coisa))
                arq.write(texto + ",\n")
                tamanho = tamanho - 1
        arq.write("\n\n]\n}")
        arq.close()

        return render_template('/synchronize.html', msg="Successfully Synchronized!")
    else:
        return render_template('/synchronize.html', msgErro="Something wrong happened, please try again later.")
Пример #13
0
def thingsTableReader():

    loca_id = request.form['location1']
    if loca_id != "0":
        things = Things ()
        location = things.search_locations ()
        resposta = []
        for i in range(0,5):
            resposta.append(startLeitura())
            # print "leitura: ",i
            # resposta.append(True)


        print "RESPOSTA ----"
        print resposta


        if False in resposta:
            return render_template ('/reader.html', locations=location, message="Error saving file.")
        elif '0' in resposta:
            return render_template ('/reader.html', locations=location, message="Erro de leitura. Tente Novamente!")
        elif 'ERRO' in resposta:
            return render_template ('/reader.html', locations=location, message="Erro na busca do objeto. Tente novamente !")
        else:
            #
            # things = Things()
            # array = things.search_things_actives_by_location(loca_id)

            return render_template('/reader.html',locationId = loca_id, locations=location, thingsdata=resposta)


    else:
        msg = "Please, Select a Location to Read."
        things = Things ()
        location = things.search_locations ()
        return render_template ('/reader.html', locations=location, message=msg)
Пример #14
0
def listLocationWriter():
    things = Things ()
    location = things.search_locations ()

    return render_template ('/writer.html', locations=location)
Пример #15
0
def locations():
    things = Things ()
    location = things.search_locations ()

    return render_template('/things.html', location=location)
Пример #16
0
def startLeitura():
    continue_reading = True
    # Hook the SIGINT
    # signal.signal(signal.SIGINT, end_read)

    is_main_thread()
    # Create an object of the class MFRC522
    MIFAREReader = MFRC522.MFRC522()
    array = []
    # This loop keeps checking for chips. If one is near it will get the UID and authenticate
    while continue_reading:

        print "ok 1"
        (status, TagType) = MIFAREReader.MFRC522_Request (MIFAREReader.PICC_REQIDL)
        print "ok 2"
        # If a card is found
        if status == MIFAREReader.MI_OK:
            print "ok 3"
            print "Card detected"

        # Get the UID of the card
            (status, uid) = MIFAREReader.MFRC522_Anticoll ()
            print "ok 4"
        # If we have the UID, continue
        # if status == MIFAREReader.MI_OK:
            print "ok 5"
            # Print UID
            # print "Card read UID: " + str (uid[0]) + "," + str (uid[1]) + "," + str (uid[2]) + "," + str (uid[3])

            # This is the default key for authentication
            key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]

            # Select the scanned tag
            MIFAREReader.MFRC522_SelectTag (uid)
            print "ok 6"
            # Sector
            sectorBlock = 1
            # sectorBlock2 = 2

            # Authenticate
            status = MIFAREReader.MFRC522_Auth (MIFAREReader.PICC_AUTHENT1A, sectorBlock, key, uid)

            print("ok 7")

            # Check if authenticated
            # if status == MIFAREReader.MI_OK:
            numero = MIFAREReader.MFRC522_Read (sectorBlock)
            print "ok 8"

            print "NUMERO"
            print numero




            things = Things()
            a = things.search_things_by_num2 (numero)

            if a == False:
                return '0'
            elif a == "ERRO":
                return 'ERRO'
            else:
                # array.append(things.search_things_by_num2 (numero))
                emiteSomOk ()
                return things.search_things_by_num2 (numero)



                # else:
                #     emiteSomErro()
                    # yield "Tag already read !!"
            MIFAREReader.MFRC522_StopCrypto1 ()