Exemplo n.º 1
0
def compra(assento, espetaculo, cartao):

    assento = assento.split('<')[1]
    assento = assento.split('>')[0]

    espetaculo = espetaculo.split('<')[1]
    espetaculo = espetaculo.split('>')[0]

    cartao = cartao.split('<')[1]
    cartao = cartao.split('>')[0]

    host = HOST_TS
    port = PORT_TS
    tsname = espetaculo

    ts = NetWorkSpace(tsname, host, port)

    try:
        seat = ts.fetchTry(assento)
        ts.deleteVar(seat)

        if (seat == None):
            exit(0)

        #Envio para fila de mensagens
        connection = pika.BlockingConnection(
            pika.ConnectionParameters(host='localhost'))
        channel = connection.channel()

        channel.queue_declare(queue='pendentes')

        channel.basic_publish(exchange='',
                              routing_key='pendentes',
                              body=cartao + '-' + seat)
        print(" [x] Mensagem recebida'")

        connection.close()

        aprovado = fila(assento)

        if aprovado == 1:
            retorno = '<link rel="stylesheet" type="text/css" media="screen" href="../static/index.css" />'
            retorno += "<h1>Compra aprovada! Obrigado por comprar conosco :D</h1>"
            retorno += '<br><br><button class="show"><a href="/">Home</a></button>'
            return retorno
        elif aprovado == 0:
            ts.store(seat, assento)
            retorno = '<link rel="stylesheet" type="text/css" media="screen" href="../static/index.css" />'
            retorno += "<h1>Compra reprovada :( Tente com outra forma de pagamento.</h1>"
            retorno += '<br><br><button class="show"><a href="/">Home</a></button>'
            return retorno
        else:
            retorno = '<link rel="stylesheet" type="text/css" media="screen" href="../static/index.css" />'
            retorno += "<h1>Falha na compra</h1>"
            retorno += '<br><br><button class="show"><a href="/">Home</a></button>'
            return retorno

    except:
        raise
        return "Except: Falha na compra."
Exemplo n.º 2
0
 def __init__(self, ws_name='Estoque', time_sleep=1, batch_size=10):
     self.time_sleep = time_sleep
     self.batch_size = batch_size
     #self.rmi=RMIManager()
     self.workspace = NetWorkSpace(ws_name,
                                   cfg.ts_machine_ip,
                                   cfg.ts_machine_port,
                                   persistent=True)
Exemplo n.º 3
0
def espetaculos():
    page = '<link rel="stylesheet" type="text/css" media="screen" href="../static/index.css" />'
    page += '<h1>Eventos</h1>'
    ts = NetWorkSpace("database", HOST_TS, PORT_TS)
    for i in ts.listVars(wsName='database', format='dict'):
        page += "<button class=\"show\"><a href=\"/consulta/<" + i + ">\">" + i + "</a></button><br>"
    page += '<br><br><button class="show"><a href="/">Home</a></button>'
    return page
Exemplo n.º 4
0
def consulta(espetaculo):

    form = FormCartao(request.form)

    print form.errors
    if request.method == 'POST':
        cartao = request.form['cartao']
        print cartao

    espetaculo = espetaculo.split('<')[1]
    espetaculo = espetaculo.split('>')[0]

    port = PORT_TS
    tsname = espetaculo
    host = HOST_TS

    ts = NetWorkSpace(tsname, host, port)

    seats = ""
    br = 0
    try:
        seats = '<link rel="stylesheet" type="text/css" media="screen" href="../static/index.css" />'
        lista = ts.listVars(wsName=tsname, format='dict')
        if not (lista):
            seats += "<h1> Sinto muito! Evento esgotado. </h1>"
        else:
            seats += '<form action="" method="post">'
            seats += '{{ form.csrf }}'
            seats += '<div class="input text">'
            seats += '{{ form.cartao.label }} {{ form.cartao }}'
            seats += '</div><br>'
            seats += '<button type="submit">Confirmar cartao</button>'
            seats += '</form>'

            if form.validate():
                seats += "<h1> Assentos </h1>"
                for i in sorted(lista):
                    seats += "<a href=\"/compra/<" + i + ">/<" + espetaculo + ">/<" + cartao + ">\"><button>"
                    seats += i
                    seats += "</button></a>"
                    br += 1
                    if (br == 10):
                        seats += "<br>"
                        br = 0

        seats += '<br><br><button class="show"><a href="/">Home</a></button>'
    except:
        raise
        seats = "There's no more seats. Sorry :("

    return render_template_string(seats, form=form)
Exemplo n.º 5
0
#start tuple space - twistd -y /etc/nws.tac
#deleteVar() - deleta
#find() - return a value
#store() - insere no espaco 
#fetch() - retira do espaco
#fetchTry() - retira nao bloqueante

port = 8765
host = sys.argv[1]

shows = ["Red Hot Chili Peppers", "ACDC", "Linkin Park", "Iron Maiden"]

for tsname in shows:

    data = NetWorkSpace("database", host, port, persistent=True)
    data.declare(tsname, 'fifo')
    data.store(tsname, tsname)

    ts = NetWorkSpace(tsname, host, port, persistent=True)

    alpha = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

    try:
        for i in alpha[:10]:
            for j in range(10):
                ts.declare("%s%d" % (i, j), 'fifo')
                ts.store("%s%d" % (i, j), "%s%d" % (i, j))
        print("Creation successful!")
    except:
        print ("Creation failed.")
Exemplo n.º 6
0
from nws.client import NetWorkSpace
import sys

#twistd -y /etc/nws.tac

port = 8765

try:
    ts = NetWorkSpace(sys.argv[1], sys.argv[2], port, persistent=True)

    print("Creation successful!")
except:
    print("Creation failed.")
    print("start_tuplespace.py <tuplespace_name> <host>")
Exemplo n.º 7
0
 def __init__(self):
     self.ws = NetWorkSpace('Estoque', cfg.ts_machine_ip, cfg.ts_machine_port, persistent=True)
Exemplo n.º 8
0
 def __init__(self):
     self.ws = NetWorkSpace('Estoque', '192.168.1.102', persistent=True)