iro/anbieter/smstrade.py
changeset 25 7295e27e8c99
parent 23 0180b538ed74
child 37 6e5bd561ddd0
--- a/iro/anbieter/smstrade.py	Tue Nov 24 02:10:48 2009 +0100
+++ b/iro/anbieter/smstrade.py	Fri Nov 27 01:14:51 2009 +0100
@@ -21,6 +21,9 @@
 import gsm0338
 import urllib, httplib
 
+import logging
+logger=logging.getLogger("smstrade")
+
 class UnknownStatusCode(Exception):
     def __init__(self,code):
         self.code=code
@@ -88,13 +91,10 @@
 
     def sendSMS(self,sms,recipients):
         """send SMS with $sms to $recipients"""
-        import logging
-        logging.debug('smstrade.sendSMS(%s,%s)'%(sms,  str(recipients)))
+        logger.debug('smstrade.sendSMS(%s,%s)'%(sms,  str(recipients)))
         sended = []
-        key = self.key
         route = unicode(self.route)
         message = sms.content
-        from_ = unicode(self.from_)
         timestamp = None
         for recipient in recipients:
             try:
@@ -107,7 +107,8 @@
                     route=unicode("basic")
                 else:
                     route=unicode("economy")
-                smsSendStatus = self.__send(key, route, to, message, from_, timestamp)	
+                smsSendStatus = self.__send(route, to, message, timestamp)	
+                logger.debug('smstrade._send(...)=%i(%s)'%(int(smsSendStatus),str(smsSendStatus)))
                 if int(smsSendStatus) in(100, 999):
                     self.updateStatus(arranged=recipient)
                 else:
@@ -115,13 +116,12 @@
             except (NotATelNumber,NoValidStatusCode,InternetConnectionError):
                 self.updateStatus(failed=recipient)
 
-    def __send(self, key, route, to, message, from_=None, timestamp=None):
+    def __send(self, route, to, message,  timestamp=None):
         """ This function is the main part of the request to the sms service.    
         The function has to return a unicode formated string that will represent the answer of the sms service
         to the request."""
-        import logging
-        logging.debug('smstrade._send(%s,%s,%s,%s,%s,%s)'%( key, route, to, message, from_,  timestamp))
-        parameters= {"key": key,
+        logger.debug('smstrade._send(%s,%s,%s,%s)'%( route, to, message, timestamp))
+        parameters= {"key": self.key,
                 "route": route,
                 "to": to,
                 "message": message,
@@ -129,15 +129,15 @@
                 "debug": self.debug,
                 }
         
-        if from_ is not None:
-            parameters["from"] = from_
+        if self.from_ is not None:
+            parameters["from"] = self.from_
         
         if timestamp is not None:
             parameters["senddate"] = unicode(timestamp)
 
         parameters["concat_sms"] = "1" if len(message) > 160 else "0"
         params = "&".join( ["%s=%s" % (urllib.quote(k),urllib.quote(v.encode("utf-8"))) for (k, v) in parameters.items()])
-        logging.debug('smstrade._send-parameters:%s\n\t->%s'%(str(parameters), str(params)) )
+        logger.debug('smstrade._send-parameters:%s\n\t->%s'%(str(parameters), str(params)) )
         headers = {"Content-type": "application/x-www-form-urlencoded",
             "Accept": "text/plain"}
         conn = httplib.HTTPConnection("%s:%i" % (self.gateway, self.gatewayPort))