Beispiel #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."
Beispiel #2
0
class TSManager:

    def __init__(self):
        self.ws = NetWorkSpace('Estoque', cfg.ts_machine_ip, cfg.ts_machine_port, persistent=True)

    def put(self, item_name, quantity):
        self.ws.store(item_name, quantity)

    def get(self, item_name):
        available = self.ws.fetchTry(item_name)
        return available

    def checkStock(self, content):
        new_order = content
        for item in new_order["items"]:
            left =  item["need"] - item["have"]
            while item["need"] > item["have"]:
                in_stock = self.get(item["name"])
                if in_stock == None:
                    break
                got = min(in_stock, left)
                item["have"] += got
                in_stock -= got
                if in_stock > 0:
                    self.put(item["name"], in_stock)

        return new_order
Beispiel #3
0
print ws.find('x')
print 'check that it is still there.'
print ws.listVars()

print 'associate another value with x.'
ws.store('x', 2)
print ws.listVars()

print 'consume values for x, should see them in order saved.'
print ws.fetch('x')
print ws.fetch('x')
print 'no more values for x... .'
print ws.listVars()

print 'so try to fetch and see what happens... .'
print ws.fetchTry('x', 'no go')

print 'create a single-value variable.'
ws.declare('pi', 'single')
print ws.listVars()

print 'get rid of x.'
ws.deleteVar('x')
print ws.listVars()

print 'try to store two values to pi.'
ws.store('pi', 2.171828182)
ws.store('pi', 3.141592654)
print ws.listVars()

print 'check that the right one was kept.'