Пример #1
0
 def fill_queue(self):
     """
     will fill the queue back up to however many it can
     will only try once
     """
     
     desired_sms = self.MAX_SMS - len(self.sms_queue)    
     data_dict = {
         'max_sms' : desired_sms,
         'key' : self.key
     }
     
     result = requests.get(self.url, params=data_dict)        
     if not result.status_code == requests.codes.ok:
         logger.log_error(self, "error filling queue: %d - %s" % (result.status_code, result.error))
         log_response(result)
         return 0
     
     count = result.json['sms_count']
     
     for sms in result.json['sms']:
         new_sms = SMS.from_dictionary(sms)
         self.sms_queue.append(new_sms)
     
     if VERBOSE:
         logger.log(self, "grabbed %s messages from django queue" % count)
     
     return len(self.sms_queue)
Пример #2
0
 def fill_queue(self):
     """
     Will attempt to GET enough SMSs from the URL to fill the internal queue
     back to MAX_SMS. If there are 5 in the queue, and MAX_LENGTH is 12, 7
     will be requested.
     
     Sens an HTTP GET request to the URL with the following parameters:
     max_sms, key
     
     Returns the new length of the sms_queue
     """
     current_length = len(self.sms_queue)
     desired_sms = self.MAX_SMS - current_length  
     data_dict = {
         'max_sms' : desired_sms,
         'key' : self.key
     }
     
     # Make the request
     result = requests.get(self.url, params=data_dict)      
       
     if result.status_code == requests.codes.ok: 
         for sms in result.json['sms']:
             new_sms = SMS.from_dictionary(sms)
             self.sms_queue.append(new_sms)
             
         count = result.json['sms_count']
         if VERBOSE:
             logger.log(self, "grabbed %s messages from django queue" % count)
             
         return current_length + count        
     else:
         logger.log_error(self, "error filling queue: %d - %s" % (result.status_code, result.error))
         save_error_response(result)
         return current_length
Пример #3
0
 def listen(self):
     print "Enter Your SMS:"
     sms_dict = {}
     
     sms_dict['to_number'] = raw_input("To: ")
     sms_dict['from_number'] = raw_input("From: ")
     sms_dict['body'] = raw_input("Body:\n")
     
     
     if sms_dict['to_number'] == "DO:QUIT":
         return False
                 
     sms = SMS.from_dictionary(sms_dict)
     
     logger.log_receive(self, sms)
     self.receive_callback(sms)
         
Пример #4
0
 def listen(self):
     """
     Used STDIN and STDOUT to get string values for the to,
     from, and body attributes of the sms to build.
     
     Will return False if the To parameter is 'DO:QUIT'
     """
     print "Enter Your SMS:"
     sms_dict = {}
     
     sms_dict['to_number'] = raw_input("To: ")
     sms_dict['from_number'] = raw_input("From: ")
     sms_dict['body'] = raw_input("Body:\n")
     
     
     if sms_dict['to_number'] == "DO:QUIT":
         return False
                 
     sms = SMS.from_dictionary(sms_dict)
     
     logger.log_receive(self, sms)
     self.receive_callback(sms)