Пример #1
0
 def run(self):
     while self._running:
         # check for new messages
         msg = self.modem.next_message()
     
         if msg is not None:
             # we got an sms! create RapidSMS Connection and
             # Message objects, and hand it off to the router
             c = Connection(self, msg.sender)
             m = Message(
                         connection=c, 
                         text=msg.text,
                         date=utils.to_naive_utc_dt(msg.sent)
                         )
             self.router.send(m)
             
         # process all outbound messages
         while True:
             try:
                 self.__send_sms(self._queue.get_nowait())
             except Queue.Empty:
                 # break out of while
                 break
             
         # poll for new messages
         # every POLL_INTERVAL seconds
         time.sleep(POLL_INTERVAL)
Пример #2
0
 def __init__(self, connection=None, text=None, person=None, date=None):
     if connection == None and person == None:
         raise Exception("Message __init__() must take one of: connection, person")
     self._connection = connection
     self.text = text
     self.date = ( datetime.utcnow() if date is None
                   else utils.to_naive_utc_dt(date) )
     self.person = person
     self.responses = []
     self.status = StatusCodes.NONE
     
     # a message is considered "unprocessed" until
     # rapidsms has dispatched it to all apps, and
     # flushed the responses out
     self.processed = False
    def __init__(self, connection=None, text=None, person=None, date=None):
        if connection == None and person == None:
            raise Exception(
                "Message __init__() must take one of: connection, person")
        self._connection = connection
        self.text = text
        self.date = (datetime.utcnow()
                     if date is None else utils.to_naive_utc_dt(date))
        self.person = person
        self.responses = []
        self.status = StatusCodes.NONE

        # a message is considered "unprocessed" until
        # rapidsms has dispatched it to all apps, and
        # flushed the responses out
        self.processed = False
Пример #4
0
    def run(self):
        while self._running:
            # check for new messages
            msg = self.modem.next_message(True)
            
            if msg is not None:
#                self.error("index: %s" % msg.index)
#                self._log( self.modem, "index: %s" % msg.index, "info")
            
                # we got an sms! create RapidSMS Connection and
                # Message objects, and hand it off to the router 
                c = Connection(self, msg.sender)
                
                # Try to use message sent date as timestamp
                # SOMETIMES this doesn't come over, in which
                # case use the current time
                try:
                    date=utils.to_naive_utc_dt(msg.sent)
                except:
                    date=datetime.utcnow()

                m = Message(
                            connection=c, 
                            text=msg.text,
                            date=date
                            )
                self.router.send(m)
                
                # remove the message
                #if msg.index:
                #   self.modem.command("AT+CMGD=%s" % msg.index)
                
    	    	self.modem.command('AT+CMGD="ALL",2')
            # process all outbound messages
            while True:
                try:
                    self.__send_sms(self._queue.get_nowait())
                except Queue.Empty:
                    # break out of while
                    break
                
            # poll for new messages
            # every POLL_INTERVAL seconds
            time.sleep(POLL_INTERVAL)
            self.modem.command("AT+CPMS?")
Пример #5
0
    def run(self):
        while self._running:
            # check for new messages
            msg = self.modem.next_message(True)

            if msg is not None:
                #                self.error("index: %s" % msg.index)
                #                self._log( self.modem, "index: %s" % msg.index, "info")

                # we got an sms! create RapidSMS Connection and
                # Message objects, and hand it off to the router
                c = Connection(self, msg.sender)

                # Try to use message sent date as timestamp
                # SOMETIMES this doesn't come over, in which
                # case use the current time
                try:
                    date = utils.to_naive_utc_dt(msg.sent)
                except:
                    date = datetime.utcnow()

                m = Message(connection=c, text=msg.text, date=date)
                self.router.send(m)

                # remove the message
                #if msg.index:
                #   self.modem.command("AT+CMGD=%s" % msg.index)

                self.modem.command('AT+CMGD="ALL",2')
            # process all outbound messages
            while True:
                try:
                    self.__send_sms(self._queue.get_nowait())
                except Queue.Empty:
                    # break out of while
                    break

            # poll for new messages
            # every POLL_INTERVAL seconds
            time.sleep(POLL_INTERVAL)
            self.modem.command("AT+CPMS?")