Example #1
0
 def open(self):
     """Initializes sms.sluzba.cz API library."""
     self.client = SmsGateApi(
         getattr(settings, 'SMS_SLUZBA_API_LOGIN', ''),
         getattr(settings, 'SMS_SLUZBA_API_PASSWORD', ''),
         getattr(settings, 'SMS_SLUZBA_API_TIMEOUT', 2),
         getattr(settings, 'SMS_SLUZBA_API_USE_SSL', True))
 def open(self):
     """Initializes sms.sluzba.cz API library."""
     self.client = SmsGateApi(
         getattr(settings, "SMS_SLUZBA_API_LOGIN", ""),
         getattr(settings, "SMS_SLUZBA_API_PASSWORD", ""),
         getattr(settings, "SMS_SLUZBA_API_TIMEOUT", 2),
         getattr(settings, "SMS_SLUZBA_API_USE_SSL", True),
     )
Example #3
0
class SmsBackend(BaseSmsBackend):
    """SmsBackend for sms.sluzba.cz API.

    settings.py configuration constants:
      SMS_SLUZBA_API_LOGIN - sms.sluzba.cz login
      SMS_SLUZBA_API_PASSWORD - sms.sluzba.cz password
      SMS_SLUZBA_API_TIMEOUT - connection timeout to sms.sluzba.cz in seconds
      SMS_SLUZBA_API_USE_SSL - whether to use ssl via http or not
      SMS_SLUZBA_API_USE_POST - whether to use GET or POST http method

    """

    def __init__(self, fail_silently=False, **kwargs):
        super(SmsBackend, self).__init__(fail_silently=fail_silently, **kwargs)
        self.open()

    def __del__(self):
        self.close()

    def open(self):
        """Initializes sms.sluzba.cz API library."""
        self.client = SmsGateApi(getattr(settings, 'SMS_SLUZBA_API_LOGIN', ''),
                                 getattr(settings, 'SMS_SLUZBA_API_PASSWORD', ''),
                                 getattr(settings, 'SMS_SLUZBA_API_TIMEOUT', 2),
                                 getattr(settings, 'SMS_SLUZBA_API_USE_SSL', True))

    def close(self):
        """Cleaning up the reference for sms.sluzba.cz API library."""
        self.client = None

    def send_messages(self, messages):
        """Sending SMS messages via sms.sluzba.cz API.

        Note:
          This method returns number of actually sent sms messages
          not number of SmsMessage instances processed.

        :param messages: list of sms messages
        :type messages: list of sendsms.message.SmsMessage instances
        :returns: number of sent sms messages
        :rtype: int

        """
        count = 0
        for message in messages:
            message_body = unicodedata.normalize('NFKD', unicode(message.body)).encode('ascii', 'ignore')
            for tel_number in message.to:
                try:
                    self.client.send(tel_number, message_body, getattr(settings, 'SMS_SLUZBA_API_USE_POST', True))
                except Exception:
                    if self.fail_silently:
                        log.exception('Error while sending sms via sms.sluzba.cz backend API.')
                    else:
                        raise
                else:
                    count += 1

        return count
Example #4
0
 def open(self):
     """Initializes sms.sluzba.cz API library."""
     self.client = SmsGateApi(getattr(settings, 'SMS_SLUZBA_API_LOGIN', ''),
                              getattr(settings, 'SMS_SLUZBA_API_PASSWORD', ''),
                              getattr(settings, 'SMS_SLUZBA_API_TIMEOUT', 2),
                              getattr(settings, 'SMS_SLUZBA_API_USE_SSL', True))
Example #5
0
                    type=str,
                    help='sms.sluzba.cz login')
parser.add_argument('password',
                    metavar='password',
                    type=str,
                    help='sms.sluzba.cz password')
parser.add_argument('tel_number',
                    metavar='tel_number',
                    type=str,
                    help='number of SMS receiver')
parser.add_argument('--use-post',
                    action='store_true',
                    help='whether to use HTTP POST method',
                    default=False,
                    required=False)
parser.add_argument('--use-ssl',
                    action='store_true',
                    help='whether to use ssl over HTTP',
                    default=False,
                    required=False)
parser.add_argument('--timeout',
                    metavar='timeout',
                    type=float,
                    help='http connection timeout',
                    default=2,
                    required=False)
args = vars(parser.parse_args())

api = SmsGateApi(args['login'], args['password'], args['timeout'],
                 args['use_ssl'])
api.send(args['tel_number'], 'test SMS message', args['use_post'])
Example #6
0
class SmsBackend(BaseSmsBackend):
    """SmsBackend for sms.sluzba.cz API.

    settings.py configuration constants:
      SMS_SLUZBA_API_LOGIN - sms.sluzba.cz login
      SMS_SLUZBA_API_PASSWORD - sms.sluzba.cz password
      SMS_SLUZBA_API_TIMEOUT - connection timeout to sms.sluzba.cz in seconds
      SMS_SLUZBA_API_USE_SSL - whether to use ssl via http or not
      SMS_SLUZBA_API_USE_POST - whether to use GET or POST http method

    """
    def __init__(self, fail_silently=False, **kwargs):
        super(SmsBackend, self).__init__(fail_silently=fail_silently, **kwargs)
        self.open()

    def __del__(self):
        self.close()

    def open(self):
        """Initializes sms.sluzba.cz API library."""
        self.client = SmsGateApi(
            getattr(settings, 'SMS_SLUZBA_API_LOGIN', ''),
            getattr(settings, 'SMS_SLUZBA_API_PASSWORD', ''),
            getattr(settings, 'SMS_SLUZBA_API_TIMEOUT', 2),
            getattr(settings, 'SMS_SLUZBA_API_USE_SSL', True))

    def close(self):
        """Cleaning up the reference for sms.sluzba.cz API library."""
        self.client = None

    def send_messages(self, messages):
        """Sending SMS messages via sms.sluzba.cz API.

        Note:
          This method returns number of actually sent sms messages
          not number of SmsMessage instances processed.

        :param messages: list of sms messages
        :type messages: list of sendsms.message.SmsMessage instances
        :returns: number of sent sms messages
        :rtype: int

        """
        count = 0
        for message in messages:
            message_body = unicodedata.normalize('NFKD',
                                                 unicode(message.body)).encode(
                                                     'ascii', 'ignore')
            for tel_number in message.to:
                try:
                    self.client.send(
                        tel_number, message_body,
                        getattr(settings, 'SMS_SLUZBA_API_USE_POST', True))
                except Exception:
                    if self.fail_silently:
                        log.exception(
                            'Error while sending sms via sms.sluzba.cz backend API.'
                        )
                    else:
                        raise
                else:
                    count += 1

        return count
import argparse
from smssluzbacz_api.lite import SmsGateApi


parser = argparse.ArgumentParser(description='Processes login, password and receiver telephone number')
parser.add_argument('login', metavar='login', type=str, help='sms.sluzba.cz login')
parser.add_argument('password', metavar='password', type=str, help='sms.sluzba.cz password')
parser.add_argument('tel_number', metavar='tel_number', type=str, help='number of SMS receiver')
parser.add_argument('--use-post', action='store_true', help='whether to use HTTP POST method', default=False,
                    required=False)
parser.add_argument('--use-ssl', action='store_true', help='whether to use ssl over HTTP', default=False,
                    required=False)
parser.add_argument('--timeout', metavar='timeout', type=float, help='http connection timeout', default=2,
                    required=False)
args = vars(parser.parse_args())

api = SmsGateApi(args['login'], args['password'], args['timeout'], args['use_ssl'])
api.send(args['tel_number'], 'test SMS message', args['use_post'])