def send_csv(self): """ Send messages from a csv file. csv columns: Date To Status Action Message If Action is has text do not send that message """ csv_file = csv.reader(open(self.options['csv_file'])) # Print CSV Header print "Header:" , csv_file.next() , "Send:" , self.options['send'] print "" sent , missing , skipped = 0 , 0 , 0 for row in csv_file: _ , phone_number , _ , action , text = row phone_number = "+" + phone_number if action.strip() == "": try: contact = cont.Contact.objects.get_from_phone_number(phone_number) except cont.Contact.DoesNotExist as e: print "Missing:" , phone_number , " -> " , text if self.options['send']: transports.send( phone_number , text ) missing += 1 else: if self.options['send']: contact.send_message( text ) sent += 1 else: skipped += 1 print "Sent:" , sent , "Missing:" , missing , "Skipped:" , skipped
def send_message(self,text,control=False,**kwargs): if self.study_group != 'control' or control: # Make sure we don't send messages to the control group # Send message over system transport try: msg_id, msg_success, external_data = transports.send(self.phone_number(),text) except transports.TransportError as e: msg_id = '' msg_success = False external_data = {'error':str(e)} else: text = 'CONTROL NOT SENT: ' + text msg_id = 'control' msg_success = False external_data = {} # Create new message new_message = self.message_set.create( text=text, connection=self.connection(), external_id=msg_id, external_success=msg_success, external_data=external_data, **kwargs) return new_message
def send_message(self, text, control=False, **kwargs): if self.study_group != 'control' or control: # Make sure we don't send messages to the control group # Send message over system transport try: msg_id, msg_success, external_data = transports.send( self.phone_number(), text) except transports.TransportError as e: msg_id = '' msg_success = False external_data = {'error': str(e)} else: text = 'CONTROL NOT SENT: ' + text msg_id = 'control' msg_success = False external_data = {} # Create new message new_message = self.message_set.create(text=text, connection=self.connection(), external_id=msg_id, external_success=msg_success, external_data=external_data, **kwargs) return new_message
def send_message(self,text,**kwargs): # Send message over system transport try: msg_id, msg_success, external_data = transports.send(self.identity,text) except transports.TransportError as e: msg_id = "" msg_success = False external_data = {"error":str(e)} # Create new message new_message = self.message_set.create( text=text, connection=self, external_id=msg_id, external_success=msg_success, external_status="Sent" if msg_success else external_data.get("status","Failed"), external_data=external_data, **kwargs) return new_message
def send_message(self, text, control=False, **kwargs): # Control check - don't send messages to participants in the control if self.study_group == 'control' and control is False: text = 'CONTROL NOT SENT: ' + text msg_id = 'control' msg_success = False external_data = {} # Status check - don't send messages to participants with NO_SMS_STATUS elif self.status in Contact.NO_SMS_STATUS and control is False: text = 'STATUS {} NOT SENT: '.format(self.status.upper()) + text msg_id = self.status msg_success = False external_data = {} else: # Send message over system transport try: msg_id, msg_success, external_data = transports.send( self.phone_number(), text) except transports.TransportError as e: msg_id = "" msg_success = False external_data = {"error": str(e)} # Create new message new_message = self.message_set.create( text=text, connection=self.connection(), external_id=msg_id, external_success=msg_success, external_status="Sent" if msg_success else external_data.get( "status", "Failed"), external_data=external_data, **kwargs) return new_message