Example #1
0
class AttendantServer(protocol.Protocol):
    def __init__(self):
        self.attendant = Attendant()

    def dataReceived(self, data):
        total = 0
        alcoholic = False
        print data
        try:
            message = json.loads(data)
            print("Message received")
            if message['msg_type'] == 'customer_arrived':
                msg = Message('greeting', 'Hello, how are you doing?')

            elif message['msg_type'] == 'greeting':
                msg = Message('give_items',"")

            elif message['msg_type'] == 'process_items':
                items = message['items']
                alcoholic = self.attendant.process_item_list(items)
                if alcoholic:
                    msg = Message('show_age_proof',"")

            elif message['msg_type'] == 'age_proof':
                age_proof = message['hasAgeProof']
                if not age_proof:
                    self.attendant.remove_alcoholic()
                msg = Message('get_payment',"")

            elif message['msg_type'] == 'process_card':
                has_card = message['hasDebitOrCreditCard']
                payment = 0
                if has_card:
                    msg = Message('success',"")
                else:
                    msg = Message('failure',"")

            elif message['msg_type'] == 'process_cash':
                cash = message['cashOnHand']
                payment = self.attendant.process_cash(cash)
                if payment:
                    msg = Message('success',"")
                else:
                    msg = Message('insufficient_funds',"")

            elif message['msg_type'] == 'complete' or message['msg_type'] == 'reject':
                self.attendant.become_idle()
                msg = Message('next_customer',"")

            msg_json = json.dumps(msg, default=lambda o: o.__dict__)
            print msg_json
            self.transport.write(msg_json)

        except Exception as e:
            print e.message
            self.transport.write("Buddy!, you screwed up! in AttendantServer:(")
            pass
Example #2
0
 def __init__(self):
     self.attendant = Attendant.Attendant()
 def __init__(self):
     self.attendant = Attendant()