iro/anbieter/smstrade.py
changeset 21 e6302069d772
parent 20 0d7ffb9b2c7f
child 22 8b363361ba55
equal deleted inserted replaced
20:0d7ffb9b2c7f 21:e6302069d772
    89     def sendSMS(self,sms,recipients):
    89     def sendSMS(self,sms,recipients):
    90         """send SMS with $sms to $recipients"""
    90         """send SMS with $sms to $recipients"""
    91         import logging
    91         import logging
    92         logging.debug('smstrade.sendSMS(%s,%s)'%(sms,  str(recipients)))
    92         logging.debug('smstrade.sendSMS(%s,%s)'%(sms,  str(recipients)))
    93         sended = []
    93         sended = []
    94         key = self.key
       
    95         route = unicode(self.route)
    94         route = unicode(self.route)
    96         message = sms.content
    95         message = sms.content
    97         from_ = unicode(self.from_)
       
    98         timestamp = None
    96         timestamp = None
    99         for recipient in recipients:
    97         for recipient in recipients:
   100             try:
    98             try:
   101                 tel = telnumber(recipient)                
    99                 tel = telnumber(recipient)                
   102                 if tel in sended:                                             #only send message once per recipient
   100                 if tel in sended:                                             #only send message once per recipient
   105                 to ='00'+tel.land+tel.number
   103                 to ='00'+tel.land+tel.number
   106                 if tel.land == '49':
   104                 if tel.land == '49':
   107                     route=unicode("basic")
   105                     route=unicode("basic")
   108                 else:
   106                 else:
   109                     route=unicode("economy")
   107                     route=unicode("economy")
   110                 smsSendStatus = self.__send(key, route, to, message, from_, timestamp)	
   108                 smsSendStatus = self.__send(route, to, message, timestamp)	
   111                 if int(smsSendStatus) in(100, 999):
   109                 if int(smsSendStatus) in(100, 999):
   112                     self.updateStatus(arranged=recipient)
   110                     self.updateStatus(arranged=recipient)
   113                 else:
   111                 else:
   114                     self.updateStatus(failed=recipient)
   112                     self.updateStatus(failed=recipient)
   115             except (NotATelNumber,NoValidStatusCode,InternetConnectionError):
   113             except (NotATelNumber,NoValidStatusCode,InternetConnectionError):
   118     def __send(self, key, route, to, message, from_=None, timestamp=None):
   116     def __send(self, key, route, to, message, from_=None, timestamp=None):
   119         """ This function is the main part of the request to the sms service.    
   117         """ This function is the main part of the request to the sms service.    
   120         The function has to return a unicode formated string that will represent the answer of the sms service
   118         The function has to return a unicode formated string that will represent the answer of the sms service
   121         to the request."""
   119         to the request."""
   122         import logging
   120         import logging
   123         logging.debug('smstrade._send(%s,%s,%s,%s,%s,%s)'%( key, route, to, message, from_,  timestamp))
   121         logging.debug('smstrade._send(%s,%s,%s,%s)'%( route, to, message, timestamp))
   124         parameters= {"key": key,
   122         parameters= {"key": self.key,
   125                 "route": route,
   123                 "route": route,
   126                 "to": to,
   124                 "to": to,
   127                 "message": message,
   125                 "message": message,
   128                 "charset":"utf-8", 
   126                 "charset":"utf-8", 
   129                 "debug": self.debug,
   127                 "debug": self.debug,
   130                 }
   128                 }
   131         
   129         
   132         if from_ is not None:
   130         if self.from_ is not None:
   133             parameters["from"] = from_
   131             parameters["from"] = self.from_
   134         
   132         
   135         if timestamp is not None:
   133         if timestamp is not None:
   136             parameters["senddate"] = unicode(timestamp)
   134             parameters["senddate"] = unicode(timestamp)
   137 
   135 
   138         parameters["concat_sms"] = "1" if len(message) > 160 else "0"
   136         parameters["concat_sms"] = "1" if len(message) > 160 else "0"