Beispiel #1
0
def callback(ch, method, properties, body):
    decoded_body = json.loads(body.decode('utf-8'))
    to_username = decoded_body['username']
    from_address = decoded_body['fromAddress']
    from_username = contract.call().getUsernameForAddress(from_address).rstrip('\x00')

    if 'months' in decoded_body:
        messenger.send(to_username=to_username,
                       from_username=from_username,
                       months=decoded_body['months'])
    else:
        response = contract.call().checkUsernameVerified(to_username.encode('utf-8'))
        val = decoded_body['val']

        if not response:
            client = pymongo.MongoClient('localhost', 27017)
            db = client.extend
            db.message.insert_one({'username': to_username, 'lastSentTipMessage': time.time()})

            print('sending message to: ' + to_username)
            messenger.send(to_username=to_username,
                           from_username=from_username,
                           eth_amount=val)

            client.close()
Beispiel #2
0
    def update(self):
        """Get the next message from the TCP buffer if available, and add
        to inbox.
        Send the next message in the outbox if it is not empty.
        """
        recv_list, send_list, error_list = \
            select.select([self.conn], [self.conn], [self.conn], 0)

        # if my socket is ready to send out on, send the next thing
        # in the outbox.
        for i in send_list:
            if len(self.outbox) > 0:
                messenger.send(i, self.outbox.popleft())

        # if my socket is ready to read from, read in the data and add it to
        # the inbox.
        for i in recv_list:
            try:
                msg = messenger.recv(i)
                print "<got '{}'>".format(msg)
                self.inbox.append(msg)
            except messenger.ClosedConnection:
                self.close()

        for i in error_list:
            print "<socket exception...>"
            self.close()
Beispiel #3
0
def respond_adder(success, username, card_serial):
    # type (bool, str, str) -> None
    message = {
        'type': ACK if success else ERROR,
        'message': '{} ({})'.format(card_serial, username)
    }

    messenger.send(ADDER_SOCKET_NAME, message)
Beispiel #4
0
    def update(self, display):
        self.entitysystem.update();
        self.entitysystem.draw();
        messenger.send("render");

        # Delay addition and removal of entites by one game loop cycle
        while len(self.entitysystem.functions) > 0:
            self.entitysystem.functions.pop(0)()
        print("update play state.")
Beispiel #5
0
def main():
    # type: () -> None
    pn532 = Pn532_i2c()
    pn532.SAMconfigure()

    print('Reader started')
    while True:
        card_data = pn532.read_mifare().get_data()
        serial_number = get_serial(card_data)
        messenger.send('/tmp/worker', {'type': 'read', 'value': serial_number})
        sleep(READ_INTERVAL)
Beispiel #6
0
    def update(self, display):
        for event in self.pygame.event.get():
            
            if event.type == QUIT:
                self.pygame.quit()
                sys.exit()
            elif event.type == KEYDOWN and (event.key == K_x):
                print("x pressend")
                messenger.send('x');

        display.blit(self.splashtext, (0, 0))
        print("update splash state.")
Beispiel #7
0
def callback(ch, method, properties, body):
    try:
        phones, mails, msg = parse_body(body)
        logging.debug('Trying to send message...')
        try:
            messenger.send(phones, mails, msg)
            ch.basic_ack(delivery_tag=method.delivery_tag)
            logging.debug('Message was processed')
        except Exception as e:
            logging.warn('Sending problem: %r' % (str(e),))
            logging.debug('Message was NOT processed')
    except Exception as e:
        ch.basic_ack(delivery_tag=method.delivery_tag)
        logging.error('Message discarted because error parsing json: %r' % (
            str(e),))
Beispiel #8
0
def callback(ch, method, properties, body):
    try:
        phones, mails, msg = parse_body(body)
        logging.debug('Trying to send message...')
        try:
            messenger.send(phones, mails, msg)
            ch.basic_ack(delivery_tag=method.delivery_tag)
            logging.debug('Message was processed')
        except Exception as e:
            logging.warn('Sending problem: %r' % (str(e), ))
            logging.debug('Message was NOT processed')
    except Exception as e:
        ch.basic_ack(delivery_tag=method.delivery_tag)
        logging.error('Message discarted because error parsing json: %r' %
                      (str(e), ))
	def undo(self):		#TODO: write test to this
		"""
		Execute an action that cancels the action of this command
		"""			
		self.undocmd(self)
		self._undoed = 1
		messenger.send(None, "execute_command", self, 1)
		
		# If we got a callable object instead of code as string, then we need to 
		# use inspect to get the source code so we can record it
		if not self.undo_code:
			code = inspect.getsource(self.undo)
		else:
			code = self.undo_code
		messenger.send(None, "record_code", code, self.imports)		
Beispiel #10
0
    def undo(self):  #TODO: write test to this
        """
		Execute an action that cancels the action of this command
		"""
        self.undocmd(self)
        self._undoed = 1
        messenger.send(None, "execute_command", self, 1)

        # If we got a callable object instead of code as string, then we need to
        # use inspect to get the source code so we can record it
        if not self.undo_code:
            code = inspect.getsource(self.undo)
        else:
            code = self.undo_code
        messenger.send(None, "record_code", code, self.imports)
Beispiel #11
0
    def run(self, recordOnly=0):  #TODO: write test to this
        """
		Execute the action associated with this command
		"""
        # If we got a callable object instead of code as string, then we need to
        # use inspect to get the source code so we can record it
        if not self.do_code:
            code = inspect.getsource(self.toDo)
        else:
            code = self.do_code
        messenger.send(None, "record_code", code, self.imports)

        if not recordOnly:
            self.toDo(self)
            self._undoed = 0
        messenger.send(None, "execute_command", self)
	def run(self, recordOnly = 0): #TODO: write test to this
		"""
		Execute the action associated with this command
		""" 
		# If we got a callable object instead of code as string, then we need to 
		# use inspect to get the source code so we can record it
		if not self.do_code:
			code = inspect.getsource(self.toDo)
		else:
			code = self.do_code
		messenger.send(None, "record_code", code, self.imports)
	
		if not recordOnly:
			self.toDo(self)
			self._undoed = 0
		messenger.send(None, "execute_command", self)
Beispiel #13
0
def send_on_messenger_trad(dest, dest_type):
    r = sr.Recognizer()
    file = sr.AudioFile(FileNameTmp)
    with file as source:
        audio = r.record(source)
        input_sentence = "Maurice n'a pas compris votre phrase."
        try:
            # for testing purposes, we're just using the default API key
            # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
            # instead of `r.recognize_google(audio)`
            input_sentence = r.recognize_google(audio, language="fr-FR")

        except sr.UnknownValueError:
            print(
                "Google Speech Recognition n'a pas pu comprendre votre phrase")
        except sr.RequestError as e:
            print(
                "Problèmes lors de la réception du résultat de la requête de Google Speech Recognition service; {0}"
                .format(e))
    send(FileNameTmp, input_sentence, dest, dest_type)
Beispiel #14
0
def main():
    listener = Listener('/tmp/adder', 'AF_UNIX')

    if len(sys.argv) == 1:
        print('Enter new users name')
        name = input('>')
    else:
        name = ' '.join(sys.argv[1:])
    if messenger.send('/tmp/worker', {'type': 'add', 'value': name}):
        print('Now read a card with reader')

        conn = listener.accept()
        msg = conn.recv()

        if msg['type'] == 'ack':
            print('User added')
        else:
            print('Error: ' + msg['value'])
    else:
        print("Couldn't establish connection with worker")

    conn.close()
    listener.close()
Beispiel #15
0
 def _send(self, conn):
     '''Send any messages that are in the outbox.
     '''
     msg = self.user_sockets[conn].outbox.popleft()
     print "<sending '{}'>".format(msg)
     messenger.send(conn, msg)
Beispiel #16
0
def draw():
    #    for entity in entities:
    #        entity.render()
    messenger.send("render")
    pass
Beispiel #17
0
def handle_input():
    for event in pygame.event.get():

        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        elif event.type == KEYDOWN and (event.key == K_SPACE
                                        or pygame.key.get_mods() & KMOD_SHIFT):
            for entity in entities:
                if isinstance(entity, Ship):
                    add(entity.shoot())
                    messenger.send("shoot")
                    break

    keys = pygame.key.get_pressed()

    if keys[K_LEFT]:
        messenger.send("left")

    if keys[K_RIGHT]:
        messenger.send("right")

    if keys[K_UP]:
        messenger.send("accelerate")
    if keys[K_x]:
        print("x pressend")
        messenger.send('x')
    else:
        messenger.send("decelerate")
Beispiel #18
0
def send_on_messenger(dest, dest_type):
    send(FileNameTmp, "", dest, dest_type)
Beispiel #19
0
def draw():
#    for entity in entities:
#        entity.render()
    messenger.send("render");
    pass
Beispiel #20
0
def handle_input():
    for event in pygame.event.get():
            
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        elif event.type == KEYDOWN and (event.key == K_SPACE or pygame.key.get_mods() & KMOD_SHIFT):
            for entity in entities:
                if isinstance(entity, Ship):
                    add(entity.shoot())
                    messenger.send("shoot")
                    break

    keys = pygame.key.get_pressed();

    if keys[K_LEFT]: 
        messenger.send("left")
         
    if keys[K_RIGHT]:
        messenger.send("right")
        
    if keys[K_UP]:  
        messenger.send("accelerate")
    if keys[K_x]:
        print("x pressend")
        messenger.send('x');
    else: 
        messenger.send("decelerate")