Exemplo n.º 1
0
def main():
    global order_topic, address_topic
    logging.basicConfig(level=logging.DEBUG)
    logging.info("Start of main.")
    config = getConfig()
    #orderMessenger = messaging.Messaging(config, "orderClient", on_order_message, order_topic)
    orderMessenger = messaging.Messaging(config, "orderClient")
    print("starting orderMessenger")
    orderMessenger.loop_start()

    addressMessenger = messaging.Messaging(config, "addressClient", address_topic, on_address_message)
    print("starting addressMessenger")
    addressMessenger.loop_start()

    # Create an address object and an order object. Encode them as json and publish them.
    adr = Order.Address("12A", 'Main St.')
    ord = Order('shoes', 12.99, adr)
    ordStr = ord.to_json()
    adrStr = adr.to_json()

    while(True):
        orderMessenger.publish(order_topic, ordStr, 2)
        time.sleep(1)
        addressMessenger.publish(address_topic, adrStr, 2)
        time.sleep(1)
Exemplo n.º 2
0
def loginpage():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        msg = messaging.Messaging()
        msg.send('GETHASH', { 'username': username })
        response = msg.receive()
        if response['success'] != True:
            return "Login failed."
        if check_password_hash(response['hash'], password):
            session['username'] = username
            session['cocktailname'] = None
            session['thumbnail'] = None
            session['category']=None
            session['instructions']=None
            session['ingredients']=None
            session['measurements']=None
            session['ingredientname']=None
            session['ingredientdescription']=None
            session['ingredienttype']=None
            session['ingredientalchohol']=None
            session['favorite']=False
            return redirect('/userpage')
        else:
            return "Login failed."
    return render_template('login.html')
Exemplo n.º 3
0
 def __init__(self):
     self.status = status.Status()
     self.formats = formats.Format()
     self.msg =  messaging.Messaging()
     self.enf2 = enf2.ENF2()
     
     self.PC1001 = {"ALL":"allTheTen", "Field":"PCI Unit_Number", "S":self.status.c, 
                     "F":self.formats.get_format("AS10"), "MSG":msg.ENF021, "ENF":enf2.ENF021},
                     
     self.PCI002 = {"ALL":"allTheTen", "Field":"PCI Unit Name", "S":self.status.c, 
                     "F":self.formats.get_format("AS50"), "MSG":msg.ENF021, "ENF":enf2.ENF021}
                     
     self.PCI003 = {"ALL":"allTheTen", "Field":"PCI Floor Number", "S":self.status.c, 
                     "F":self.formats.get_format("AS10"), "MSG":msg.ENF021, "ENF":enf2.ENF021}
     self.PCI004 = {"ALL":"allTheTen", "Field":"PCI Plot or Street Number", "S":self.status.o, 
                     "F":self.formats.get_format("A10"), "MSG":msg.NONENFORCMENT, "ENF":enf2.NONENFORCMENT}
                     
     self.PCI005 = {"ALL":"allTheTen", "Field":"PCI LC or Street Name", "S":STATUS.o, 
             "F":self.formats.get_format("A50"), "MSG":msg.NONENFORCMENT, "ENF":enf2.NONENFORCMENT}
             
     PCI006("allTheTen", "PCI Parish", STATUS.C, FORMAT.A50, MESSAGES.ENF049,new ENF2[] { ENF2.ENF036, ENF2.ENF049 }), 
     PCI007("allTheTen","PCI Suburb", STATUS.O, FORMAT.A50, MESSAGES.NONENFORCMENT,new ENF2[] { ENF2.NONENFORCMENT }), 
     PCI008("allTheTen","PCI Village", STATUS.O, FORMAT.A50, MESSAGES.NONENFORCMENT,new ENF2[] { ENF2.NONENFORCMENT }), PCI009("allTheTen","PCI County or Town", STATUS.C, FORMAT.A50, MESSAGES.ENF036,new ENF2[] { ENF2.ENF036, ENF2.ENF049 }), 
     PCI010("allTheTen","PCI District", STATUS.C, FORMAT.A50, MESSAGES.ENF036, new ENF2[] {ENF2.ENF036, ENF2.ENF049 }), 
     PCI011("allTheTen","PCI Region", STATUS.C, FORMAT.N1, MESSAGES.ENF036, new ENF2[] {ENF2.ENF036, ENF2.ENF054, ENF2.ENF116 }), 
     PCI012("allTheTen", "PCI PO Box Number", STATUS.C, FORMAT.A10,MESSAGES.ENF014, new ENF2[] { ENF2.ENF014 }), 
     PCI013("allTheTen","PCI Post Office Town", STATUS.C, FORMAT.A20, MESSAGES.ENF014,new ENF2[] { ENF2.ENF014 }), 
     PCI014("allTheTen","PCI Country Code", STATUS.M, FORMAT.A2, MESSAGES.ENF014,new ENF2[] { ENF2.ENF065, ENF2.ENF014 }), PCI015("allTheTen","PCI Period At Address", STATUS.M, FORMAT.N3, MESSAGES.ENF014, new ENF2[] { ENF2.ENF014, ENF2.ENF116 }), 
Exemplo n.º 4
0
def loginpage():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        msg = messaging.Messaging()
        msg.send('GETHASH', {'username': username})
        response = msg.receive()
        if response['success'] != True:
            return "Login failed."
        if check_password_hash(response['hash'], password):
            session['email'] = email
            return redirect('/')
        else:
            return "Login failed."
    return render_template('login.html')
Exemplo n.º 5
0
def register():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']
        msg = messaging.Messaging()
        msg.send('REGISTER', {
            'email': email,
            'hash': generate_password_hash(password)
        })
        response = msg.receive()
        if response['success']:
            session['email'] = email
            return redirect('/')
        else:
            return f"{response['message']}"
    return render_template('register.html')
Exemplo n.º 6
0
def favorites():
    session['cocktailname'] = None
    session['thumbnail'] = None
    session['category']=None
    session['instructions']=None
    session['ingredients']=None
    session['measurements']=None
    session['ingredientname']=None
    session['ingredientdescription']=None
    session['ingredienttype']=None
    session['ingredientalchohol']=None
    session['favorite']=False
    msg = messaging.Messaging()
    msg.send(
        'getfavorites',
        {
            'username' : session['username']
        }
    )
    response = msg.receive()
    return render_template('favorites.html',data=response)
Exemplo n.º 7
0
def registerpage():
    if request.method == 'POST':
        firstname = request.form['firstname']
        lastname = request.form['lastname']
        email = request.form['email']
        username = request.form['username']
        password = request.form['password']
        confirmpassword = request.form['confirmpassword']
        if password == confirmpassword:
            msg = messaging.Messaging()
            msg.send(
                'REGISTER',
                {
                    'firstname' : firstname,
                    'lastname' : lastname,
                    'email': email,
                    'username' : username,
                    'hash': generate_password_hash(password)
                }
            )
            response = msg.receive()
            if response['success']:
                session['username'] = username
                session['cocktailname'] = None
                session['thumbnail'] = None
                session['category']=None
                session['instructions']=None
                session['ingredients']=None
                session['measurements']=None
                session['ingredientname']=None
                session['ingredientdescription']=None
                session['ingredienttype']=None
                session['ingredientalchohol']=None
                session['favorite']=False
                return redirect('/userpage')
            else:
                return f"{response['message']}"
    return render_template('register.html')
Exemplo n.º 8
0
def userpage():
    if 'username' not in session:
        return redirect('/')

    if request.method == 'POST':
        if 'btn2' in request.form:
            if session['cocktailname'] != None:
                msg = messaging.Messaging()
                msg.send(
                    'favorite',
                    {
                        'username' : session['username'],
                        'fav' : session['cocktailname']
                    }
                )
                response = msg.receive()
                if response['success']:
                    if response['deleted']:
                        session['favorite']=False
                    elif response['inserted']:
                        session['favorite']=True

        if 'btn1' in request.form:
            dropdownvalue = request.form['dropdownvalue']
            searchfield = request.form['searchfield']
            if dropdownvalue == 'cocktail_name' and searchfield == 'random':
                dropdownvalue = 'random'
            msg = messaging.Messaging()
            msg.send(
                'SCRAPE',
                {
                    'searchfield' : searchfield,
                    'dropdownvalue' : dropdownvalue,
                    'username' : session['username']
                }
            )
            response = msg.receive()
            if response['success']:
                if response['search'] == 'cocktail_name' or response['search'] == 'random':
                    session['thumbnail'] = (response['cocktailimage'])
                    session['cocktailname'] = (response['cocktailname'])
                    session['category']=(response['cocktailcategory'])
                    session['instructions']=(response['cocktailinstructions'])
                    session['ingredients']=(response['cocktailingredients'])
                    session['measurements']=(response['cocktailmeasurements'])
                    session['favorite'] = (response['favorite'])
                    session['ingredientname']=None
                    session['ingredientdescription']=None
                    session['ingredienttype']=None
                    session['ingredientalchohol']=None
                elif response['search'] == 'ingredient_name':
                    session['cocktailname']=None
                    session['thumbnail']=None
                    session['category']=None
                    session['instructions']=None
                    session['ingredients']=None
                    session['measurements']=None
                    session['ingredientname']= (response['ingredientname'])
                    session['ingredientdescription'] = (response['ingredientdescription'])
                    session['ingredienttype']= (response['ingredienttype'])
                    session['ingredientalchohol']= (response['ingredientalchohol'])
            else:
                cocktailname = "ERROR"
    return render_template('userpage.html')
Exemplo n.º 9
0
def test():
    hmi_receiver = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    # Configure Socket to allow reuse of sessions in TIME_WAIT. Otherwise, "Address already in use" is encountered
    # Per suggestion on https://stackoverflow.com/questions/29217502/socket-error-address-already-in-use/29217540
    # by ForceBru
    hmi_receiver.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    hmi_receiver.bind(("127.0.0.1", commsettings.GAME_HMI_LISTEN))
    hmi_receiver.listen(2)
    hmi_receiver_queue = queue.Queue()
    hmi_msg_controller = messaging.Messaging(commsettings.MESSAGE_BREAKER,
                                             hmi_receiver,
                                             hmi_receiver_queue,
                                             loglevel=logging.INFO,
                                             name="Game:hmi_receiver")
    hmi = threading.Thread(target=HMI)

    hmi.start()

    # Allow subsystems to spawn
    time.sleep(1)

    # Keep trying to create the sender until the correct receiver has been created

    while True:
        try:
            hmi_sender = socket.create_connection(
                ("127.0.0.1", commsettings.HMI_LISTEN))
            break
        except:
            continue

    total_tests = 0
    passes = 0
    failures = 0

    print("\nTesting comm interface between Game Logic and HMI")
    test_number = 0

    while test_number < 3:
        categorylist = ["l33t", "Aaron", "James"]
        message = dict()
        message['action'] = "promptCategorySelectByUser"
        message['arguments'] = categorylist
        test_number += 1
        hmi_msg_controller.send_string(hmi_sender, json.dumps(message))
        while hmi_msg_controller.q.empty():
            pass
            time.sleep(.1)
        response = hmi_msg_controller.q.get()
        if json.loads(response)['arguments'] in message['arguments']:
            print("\tTest Number: " + str(test_number) + "\tSent: " +
                  message['action'] + "\tReceived: " +
                  json.loads(response)['arguments'] + "\tP/F: PASS")
            total_tests += 1
            passes += 1
        else:
            print("\tTest Number: " + str(test_number) + "\tSent: " +
                  message['action'] + "\tReceived: " +
                  json.loads(response)['arguments'] + "\tP/F: FAIL")
            total_tests += 1
            failures += 1

    while test_number < 5:
        message = dict()
        message['action'] = "updateGameState"
        message['arguments'] = {
            "round":
            0,
            "totalRounds":
            2,
            "players": [{
                "name": "Aaron",
                "gameScore": 0,
                "roundScore": 0,
                "freeTurnTokens": 0
            }],
            "spinsExecuted":
            0,
            "maxSpins":
            5
        }
        test_number += 1
        hmi_msg_controller.send_string(hmi_sender, json.dumps(message))
        while hmi_msg_controller.q.empty():
            pass
            time.sleep(.1)
        response = hmi_msg_controller.q.get()
        if json.loads(response)['arguments'] == "ACK":
            print("\tTest Number: " + str(test_number) + "\tSent: " +
                  message['action'] + "\tReceived: " +
                  json.loads(response)['arguments'] + "\tP/F: PASS")
            total_tests += 1
            passes += 1
        else:
            print("\tTest Number: " + str(test_number) + "\tSent: " +
                  message['action'] + "\tReceived: " +
                  json.loads(response)['arguments'] + "\tP/F: FAIL")
            total_tests += 1
            failures += 1

    message = dict()
    message['action'] = "spinWheel"
    message['arguments'] = 5
    test_number = 0

    while test_number < 5:
        test_number += 1
        hmi_msg_controller.send_string(hmi_sender, json.dumps(message))
        while hmi_msg_controller.q.empty():
            pass
            time.sleep(.1)
        response = hmi_msg_controller.q.get()

        if json.loads(response)['arguments'] != "ACK":
            print("\tTest Number: " + str(test_number) + "\tSent: " +
                  message['action'] + "\tReceived: " +
                  json.loads(response)['arguments'] + "\tP/F: FAIL")
            total_tests += 1
            failures += 1
        else:
            print("\tTest Number: " + str(test_number) + "\tSent: " +
                  message['action'] + "\tReceived: " +
                  json.loads(response)['arguments'] + "\tP/F: PASS")
            total_tests += 1
            passes += 1

    print("\nTesting comm interface between Game Logic and Board")
    test_number = 0

    while test_number < 3:
        test_number += 1
        message = dict()
        message['action'] = "promptCategorySelectByUser"
        message['arguments'] = "0"
        hmi_msg_controller.send_string(hmi_sender, json.dumps(message))
        while hmi_msg_controller.q.empty():
            pass
            time.sleep(.1)
        response = hmi_msg_controller.q.get()
        if json.loads(response)['action'] == "responseCategorySelect":
            print("\tTest Number: " + str(test_number) + "\tSent: " +
                  message['action'] + "\tReceived: " +
                  json.loads(response)['action'] + "\tP/F: PASS")
            total_tests += 1
            passes += 1
        else:
            print("\tTest Number: " + str(test_number) + "\tSent: " +
                  message['action'] + "\tReceived: " +
                  json.loads(response)['action'] + "\tP/F: FAIL")
            total_tests += 1
            failures += 1

    while test_number < 5:
        test_number += 1
        message = dict()
        message['action'] = "displayQuestionsByCategory"
        message['arguments'] = ""
        hmi_msg_controller.send_string(hmi_sender, json.dumps(message))
        while hmi_msg_controller.q.empty():
            pass
            time.sleep(.1)
        response = hmi_msg_controller.q.get()
        if json.loads(response)['arguments'] == "ACK":
            print("\tTest Number: " + str(test_number) + "\tSent: " +
                  message['action'] + "\tReceived: " +
                  json.loads(response)['arguments'] + "\tP/F: PASS")
            total_tests += 1
            passes += 1
        else:
            print("\tTest Number: " + str(test_number) + "\tSent: " +
                  message['action'] + "\tReceived: " +
                  json.loads(response)['arguments'] + "\tP/F: FAIL")
            total_tests += 1
            failures += 1

    print("\nTotal Tests: " + str(total_tests) + "\tSuccesses: " +
          str(passes) + "\tFailures: " + str(failures) + "\n")
Exemplo n.º 10
0
 def __init__(self):
     self.status = status.Status()
     self.formats = formats.Format()
     self.msg =  messaging.Messaging()
     self.enf2 = enf2.ENF2()
     
     self.PC1001 = {"ALL":"allTheTen", "Field":"PCI Unit_Number", "S":self.status.c, 
                     "F":self.formats.get_format("AS10"), "MSG":msg.ENF021, "ENF":enf2.ENF021},
                     
     self.PCI002 = {"ALL":"allTheTen", "Field":"PCI Unit Name", "S":self.status.c, 
                     "F":self.formats.get_format("AS50"), "MSG":self.msg.ENF021, "ENF":self.enf2.ENF021}
                     
     self.PCI003 = {"ALL":"allTheTen", "Field":"PCI Floor Number", "S":self.status.c, 
                     "F":self.formats.get_format("AS10"), "MSG":self.msg.ENF021, "ENF":self.enf2.ENF021}
     self.PCI004 = {"ALL":"allTheTen", "Field":"PCI Plot or Street Number", "S":self.status.o, 
                     "F":self.formats.get_format("A10"), "MSG":self.msg.NONENFORCMENT, "ENF":self.enf2.NONENFORCMENT}
                     
     self.PCI005 = {"ALL":"allTheTen", "Field":"PCI LC or Street Name", "S":self.status.o, 
                     "F":self.formats.get_format("A50"), "MSG":self.msg.NONENFORCMENT, "ENF":self.enf2.NONENFORCMENT}
             
     self.PCI006 = {"ALL":"allTheTen", "Field":"PCI Parish", "S":self.status.c, 
                 "F":self.formats.get_format("A50"), "MSG":self.msg.ENF049 ,
                 "ENF":{"ENF2.ENF036":"ENF2.ENF036", "ENF2.ENF049":"ENF2.ENF049" }}
                 
     self.PCI007 = {"ALL":"allTheTen", "Field":"PCI Suburb", "S":self.status.o, 
                     "F":self.formats.get_format("A50"), "MSG":msg.NONENFORCMENT ,"ENF":self.enf2.NONENFORCMENT}
     
     self.PCI008 = {"ALL":"allTheTen", "Field":"PCI Village", "S":self.status.o, 
                     "F":self.formats.get_format("A50"), "MSG":self.msg.NONENFORCMENT , "ENF":self.enf2.NONENFORCMENT}
                     
     self.PCI009= {"ALL":"allTheTen", "Field":"PCI County or Town", "S":self.status.c, 
                 "F":self.formats.get_format("A50"), "MSG":self.msg.NONENFORCMENT,
                 "ENF":{"ENF2.ENF036":ENF2.ENF036, "ENF2.ENF049":ENF2.ENF049 }}
                 
     self.PCI010={"ALL":"allTheTen", "Field":"PCI District", "S":self.status.c, 
                 "F":self.formats.get_format("A50"), "MSG":self.msg.ENF036, 
                 {"ENF2.ENF036":ENF2.ENF036, "ENF2.ENF049":ENF2.ENF049 }}
                 
     self.PCI011 = {"ALL":"allTheTen", "Field":"PCI Region", "S":self.status.c, 
                     "F":self.formats.get_format("N1"), "MSG":self.msg.ENF036, 
                     {"ENF2.ENF036":"ENF2.ENF036", "ENF2.ENF054":ENF2.ENF054, 
                     "ENF2.ENF116":"ENF2.ENF116" }}
     
     self.PCI012 = {"ALL":"allTheTen", "Field":"PCI PO Box Number", "S":self.status.c, 
                     "F":self.formats.get_format("A10"), "MSG":self.msg.ENF014, "ENF":self.enf2.ENF014}
                     
     self.PCI013 = {"ALL":"allTheTen", "Field":"PCI Post Office Town", "S":self.status.c, 
                     "F":self.formats.get_format("A20"), "MSG":self.msg.ENF014 ,"ENF":self.enf2.ENF014}    
     self.PCI014 = {"ALL":"allTheTen", "Field":"PCI Country Code","S":self.status.m, 
                 "F":self.formats.get_format("A2"), "MSG":self.msg.ENF014 ,"ENF":self.enf2.ENF014 }
                 
     self.PCI015 = {"Field":"allTheTen", "Field":"PCI Period At Address", "S":self.status.m, 
                 "F":self.formats.get_format("N3"), "MSG":self.msg.ENF014,
                 "ENF2.ENF014":"ENF2.ENF014", "ENF2.ENF116":"ENF2.ENF116" } 
                 
     self.PCI016 = {"ALL":"allTheTen", "Field":"PCI Flag of Ownership", "S":self.status.m, 
                 "F":self.formats.get_format("A1"), "MSG":self.msg.ENF014, "ENF":self.enf2.ENF084 },
     
     self.PCI017 = {"ALL":"allTheTen", "Field":"PCI Primary Number Country Dialling Code", "S":self.status.m, 
                     "F":self.formats.get_format("N5"), "MSG":self.msg.ENF056, 
                     {"ENF2.ENF056":"ENF2.ENF056", "ENF2.ENF116":"ENF2.ENF116"
                     }}
                     
     self.PCI018 = {"ALL":"allTheTen", "Field":"PCI Primary Number Telephone Number", "S":self.status.m, 
             "F":self.formats.get_format("N10"), "MSG":self.msg.ENF116, "ENF":self.enf2.ENF116 }
             
     self.PCI019 = {"ALL":"allTheTen", "Field":"PCI Other Number Country Dialling Code","S":self.status.c, 
                 "F":self.formats.get_format("N5"), "MSG":self.msg.ENF116, 
                 {"ENF2.ENF116":"ENF2.ENF116", "ENF2.ENF056""ENF2.ENF056" }}
                  
     self.PCI020 = {"ALL":"allTheTen", "Field":"PCI Other Number Telephone Number", "S":self.status.c,
                  "F":self.formats.get_format("N10"), "MSG":self.msg.ENF116, "ENF":self.enf2.ENF116 }
                  
     self.PCI021 ={"ALL":"allTheTen", "Field":"PCI Mobile Number Country Dialling Code", "S":self.status.c,
                    "F":self.formats.get_format("N5"), "MSG":self.msg.ENF056, 
                    {"ENF2.ENF116":"ENF2.ENF116", "ENF2.ENF056":"ENF2.ENF056" }}
                    
     self.PCI022={"ALL":"allTheTen", "Field":"PCI Mobile Number Telephone Number", "S":self.status.c,
                 "F":self.formats.get_format("N10"), "MSG":self.msg.ENF116, "ENF":self.enf2.ENF116 }
                 
     self.PCI023 = {"ALL":"allTheTen", "Field":"PCI Facsimile Country Dialling Code", "S":self.status.c,
                     "F":self.formats.get_format("N5"), "MSG":self.msg.ENF116, 
                     {"ENF2.ENF116":"ENF2.ENF116", "ENF2.ENF056":"ENF2.ENF056"}} 
                     
     self.PCI024 = {"ALL":"allTheTen", "Field":"PCI Facsimile Number", "S":self.status.c, 
                     "F":self.formats.get_format("N10") ,"MSG":self.msg.ENF116, "ENF":self.enf2.ENF116 }
                      
     self.PCI025 = {"ALL":"allTheTen", "Field":"PCI Email Address", "S":self.status.c, 
                     "F":self.formats.get_format("AS50"), "MSG":self.msg.ENF129, "ENF":self.enf2.ENF129 }
                     
     self.PCI026 = {"ALL":"allTheTen", "Field":"PCI Website","S":self.status.c, 
                     "F":self.formats.get_format("AS50"), "MSG":self.msg.ENF129, "ENF":self.enf2.ENF129 }
                     
     self.PI001 = {"dataset":"PI", "Field":"PI Identification Code", 
                     "S":self.status.m, "F":self.formats.get_format("A6"),
                     "MSG":self.msg.ENF068, "ENF":self.enf2.ENF068 }, 
                     
     self.PI002 = {"dataset":"PI", "Field":"Institution Type", "S":self.status.m, 
                     "F":self.formats.get_format("A3"), "MSG":self.msg.ENF069,
                     "ENF":self.enf2.ENF069 }
                     
     self.PI003 = {"dataset":"PI", "Field":"Institution Name","S":self.status.m, 
                     "F":self.formats.get_format("AS100"), "MSG":self.msg.ENF129, 
                     {"ENF2.ENF014":"ENF2.ENF014", "ENF2.ENF129":"ENF2.ENF129" }}
                     
     self.PI004 = {"dataset":"PI", "Field":"License Issuing Date",
                 "S":self.status.m, "F":self.formats.get_format("N8"), 
                 "MSG":self.msg.ENF007, {"ENF2.ENF014":"ENF2.ENF014" ,"ENF2.ENF007":"ENF2.ENF007"}}
     
     self.allTheTen = "allTheTen";
     self.dataset;
     self.data_filed;
     '''