Ejemplo n.º 1
0
    def post(self):
        '''   Send a SMS'''
        json_data = request.json
        message = json_data["message"]
        numbers = json_data["recipients"]
        results = []
        for number in numbers:
            # Create SMS info structure
            smsinfo = {
                'Class': -1,
                'Unicode': True,
                'Entries': [{
                    'ID': 'ConcatenatedTextLong',
                    'Buffer': message
                }]
            }

            # Encode messages
            encoded = gammu.EncodeSMS(smsinfo)

            for sms in encoded:
                # Fill in numbers
                sms['SMSC'] = {'Location': 1}
                sms['Number'] = number

            msg_id = smsd.InjectSMS(encoded)
            results.append({"DestinationNumber": number, "smsID": msg_id})

        return {'results': results}, 200
Ejemplo n.º 2
0
    def test_smsd(self):
        smsd = self.get_smsd()

        # Inject SMS messages
        # Please note that SMSD is not thread safe, so you can not
        # use inject and main loop from different threads
        smsd.InjectSMS([MESSAGE_1])
        smsd.InjectSMS([MESSAGE_2])

        try:
            # Start SMSD thread
            smsd_thread = threading.Thread(target=smsd.MainLoop)
            smsd_thread.start()
            # We need to let it run for some time here to finish initialization
            time.sleep(10)

            # Show SMSD status
            retries = 0
            while retries < 2:
                status = smsd.GetStatus()
                if status['Sent'] >= 2:
                    break
                time.sleep(10)
                retries += 1

            self.assertEqual(
                status['Received'],
                2,
                'Messages were not received as expected (%d)!' %
                status['Received']
            )
            self.assertEqual(
                status['Sent'],
                2,
                'Messages were not sent as expected (%d)!' %
                status['Sent']
            )

            time.sleep(1)

        finally:
            # Signal SMSD to stop
            smsd.Shutdown()

            # Wait for it
            smsd_thread.join()
Ejemplo n.º 3
0
def sending_sms(requester):
    message = {
        'Text': checkpabxalmerys(),
        'SMSC': {
            'Location': 1
        },
        'Number': requester
    }
    smsd.InjectSMS([message])
Ejemplo n.º 4
0
 def send_smsd(self, phone_number, text):
     # Send SMS via smsd. Insert message in smsd send queue.
     smsd = gammu.smsd.SMSD('/etc/gammu-smsdrc')
     message = {
         'Text': text,
         'SMSC': {
             'Location': 1
         },
         'Number': phone_number,
     }
     smsd.InjectSMS([message])
Ejemplo n.º 5
0
def send_sms(section, message_inject, sender=None):

    message_inject = message_inject.decode('utf-8')
    config = ConfigParser.RawConfigParser()
    sms_config_path = os.environ['SMS_CONFIG_PATH']
    config.read(sms_config_path)

    section = config.items(section)
    config_smsd = config.get('options', 'config_smsd')

    smsd = gammu.smsd.SMSD(config_smsd)
    liste_message = message_decomp(message_inject)

    for nom, number in section:

        for message in liste_message:
            message_send = {
                'Text': unicode(message),
                'SMSC': {
                    'Location': 1
                },
                'Number': number
            }
            smsd.InjectSMS([message_send])
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
"""Sample script to show how to send SMS through SMSD"""

from __future__ import print_function
import gammu.smsd
import sys

smsd = gammu.smsd.SMSD('/etc/gammu-smsdrc')

if len(sys.argv) != 2:
    print('Usage: smsd-inject.py RECIPIENT_NUMBER')
    sys.exit(1)

message = {
    'Text': 'python-gammu testing message',
    'SMSC': {
        'Location': 1
    },
    'Number': sys.argv[1]
}

smsd.InjectSMS([message])
Ejemplo n.º 7
0
 def test_inject(self):
     smsd = self.get_smsd()
     smsd.InjectSMS([MESSAGE_1])
Ejemplo n.º 8
0
def __gammu_sms(recipient, text):
    smsd = gammu.smsd.SMSD('/etc/gammu-smsdrc')
    message = {'Text': text, 'SMSC': {'Location': 1}, 'Number': recipient}
    return smsd.InjectSMS([message])
Ejemplo n.º 9
0
def send_sms(msgbody, number):
    '''
    injects sms into gammu outbox
    '''
    message = {'Text': msgbody, 'SMSC': {'Location': 1}, 'Number': number}
    smsd.InjectSMS([message])