コード例 #1
0
    def send(self, text, phone, max_length=None, send_time=None, sender=None):
        """
        Send a message to one or more numbers.

        If the message is too long for a single SMS it will be split up into
        a maximum of three separate messages. Maximum SMS length is usually
        160 characters (unless the message contains Unicode characters in
        which case the maximum length is 70 characters). With the max_length
        parameter you can control how many parts a message is broken into.

        Parameters:
            text - the message
            phone - one phone number or a list of numbers
            max_length - (optional) maximum parts to split the message into
            send_time - (optional) time to send the message as a
                time.struct_time or as "seconds since the epoch"/Unix time

        Return:
            A textmagic.responses.SendResponse

            response['message_id'] is a dict where the keys are message ids
                (as allocated by the TextMagic system) and the values are
                the corresponding destination phone numbers
            response['sent_text'] is the message text
            response['parts_count'] is the number of parts the message was
                split into

        """
        unicode_ = is_gsm(text) and '0' or '1'
        return self._send(text, phone, max_length, send_time, unicode_, sender)
コード例 #2
0
    def send(self, text, phone, max_length=None, send_time=None, sender=None):
        """
        Send a message to one or more numbers.

        If the message is too long for a single SMS it will be split up into
        a maximum of three separate messages. Maximum SMS length is usually
        160 characters (unless the message contains Unicode characters in
        which case the maximum length is 70 characters). With the max_length
        parameter you can control how many parts a message is broken into.

        Parameters:
            text - the message
            phone - one phone number or a list of numbers
            max_length - (optional) maximum parts to split the message into
            send_time - (optional) time to send the message as a
                time.struct_time or as "seconds since the epoch"/Unix time

        Return:
            A textmagic.responses.SendResponse

            response['message_id'] is a dict where the keys are message ids
                (as allocated by the TextMagic system) and the values are
                the corresponding destination phone numbers
            response['sent_text'] is the message text
            response['parts_count'] is the number of parts the message was
                split into

        """
        unicode_ = is_gsm(text) and '0' or '1'
        return self._send(text, phone, max_length, send_time, unicode_, sender)
コード例 #3
0
 def testSomeStrings(self):
     self.assertEquals(is_gsm('Some latin text'), True)
     self.assertEquals(is_gsm(u'\uABCD'), False)
     self.assertEquals(is_gsm('{} \ ~ [ ] |'), True)  # Extended characters
     self.assertEquals(is_gsm(u'\u20AC'), True)  # Euro
     self.assertEquals(is_gsm(u'\u0041'), True)  # Latin capital A
     self.assertEquals(is_gsm(u'\u0391'), True)  # Greek capital Alpha
     self.assertEquals(is_gsm(u'\u0041\u0391'), True)  # A and Alpha
     self.assertEquals(is_gsm(u'\u2800\u2801\u2802\u2803 \u27F0'), False)
コード例 #4
0
 def testSomeStrings(self):
     self.assertEquals(is_gsm('Some latin text'), True)
     self.assertEquals(is_gsm(u'\uABCD'), False)
     self.assertEquals(is_gsm('{} \ ~ [ ] |'), True)  # Extended characters
     self.assertEquals(is_gsm(u'\u20AC'), True)  # Euro
     self.assertEquals(is_gsm(u'\u0041'), True)  # Latin capital A
     self.assertEquals(is_gsm(u'\u0391'), True)  # Greek capital Alpha
     self.assertEquals(is_gsm(u'\u0041\u0391'), True)  # A and Alpha
     self.assertEquals(is_gsm(u'\u2800\u2801\u2802\u2803 \u27F0'), False)
コード例 #5
0
ファイル: client.py プロジェクト: WeilerWebServices/textmagic
 def _send(self, text, phone, max_length, send_time, unicode_):
     if not isinstance(phone, list):
         phone = [phone]
     if isinstance(send_time, time.struct_time):
         send_time = time.mktime(send_time)
     if unicode_ is None:
         unicode_ = is_gsm(text) and '0' or '1'
     params_dict = {
         'cmd': 'send',
         'text': text.encode('utf-8'),
         'phone': str(','.join([unicode(number) for number in phone])),
         'unicode': str(unicode_),
     }
     if max_length is not None:
         params_dict['max_length'] = str(max_length)
     if send_time is not None:
         params_dict['send_time'] = str(int(send_time))
     return self._execute_command(params_dict, SendResponse)
コード例 #6
0
 def _send(self, text, phone, max_length, send_time, unicode_, sender):
     if not isinstance(phone, list):
         phone = [phone]
     if isinstance(send_time, time.struct_time):
         send_time = time.mktime(send_time)
     if unicode_ is None:
         unicode_ = is_gsm(text) and '0' or '1'
     params_dict = {
       'cmd': 'send',
       'text': text.encode('utf-8'),
       'phone': str(','.join([unicode(number) for number in phone])),
       'unicode': str(unicode_),
     }
     if sender is not None:
         params_dict["from"] = sender
     if max_length is not None:
         params_dict['max_length'] = str(max_length)
     if send_time is not None:
         params_dict['send_time'] = str(int(send_time))
     return self._execute_command(params_dict, SendResponse)