Example #1
0
    def db_storage(recipients, message, user_id, sender):
        """
        This method is responsible to store Sms and related fields provided by client in database
        """

        sms_ids = ''    # contains all message ids that are sended by client to recipient of same or different network.
        #smses_ids = ''  # contains only message ids that are sended by client to recipient of some other network.
        sender = sender.decode(encoding='ascii')
        recipients = recipients.decode(encoding='ascii').splitlines()
        selected_package = selected_packages(user_id)
        for recipient in recipients:
            processed_fields = process_outgoing_sms(sender, user_id, recipient)

        # storing vaues to database

            S = Sms()
            S.sms_type = 'outgoing'
            S.sms_from = processed_fields['sender_number']
            S.sms_to = recipient
            S.schedule_delivery_time = datetime.date.today()
            S.validity_period = datetime.date.today()+datetime.timedelta(days=1)
            S.msg = message
            S.timestamp = datetime.date.today()
            S.status = 'scheduled'
            S.msg_type = 'text'
            S.user_id = user_id
            S.package_name = selected_package['package_name']
            S.rates = selected_package['rates']
            S.target_network = processed_fields['target_network']  # process sms file would use it to send to respective network of which server is.
            S.client_type = 'smpp'
            DBSession.add(S)
            transaction.commit()
            sms = DBSession.query(Sms)[-1]  # to send id to the client for ancilliary operations and querying.
            sms_ids = sms_ids + str(sms.id) + '\n'
            if processed_fields['target_network'] != processed_fields['source_network']:  # if destination and source network is different 
                connect_info(recipient, message, processed_fields['target_network'], sms.id,
                             processed_fields['sender_number'])  # connect to the destination's smpp server.
                #smses_ids = smses_ids + str(s) + '\n'
        #updating_status(smses_ids)
        return(sms_ids)
Example #2
0
import hashlib
import transaction
from smpp5.lib.util.hex_print import hex_convert, hex_print
from smpp5.lib.parameter_types import Integer, CString, String, TLV
from smpp5.lib.pdu.session_management import *
from smpp5.lib.constants import interface_version as IV
from smpp5.lib.pdu.session_management import BindTransmitter, BindTransmitterResp, BindReceiver, BindReceiverResp, BindTransceiver, BindTransceiverResp, OutBind, UnBind, UnBindResp, EnquireLink, EnquireLinkResp, AlertNotification, GenericNack
from smpp5.lib.constants import *
from sqlalchemy import func
import datetime

if '__main__' == __name__:
    db.bind_session()
    d = datetime.date.today()-datetime.timedelta(days=4)
    S = Sms()
    S.sms_type = 'outgoing'
    S.sms_from = '+9233365195924'
    S.sms_to = '+923366767999'
    S.schedule_delivery_time = d   # give date 2nd december
    S.validity_period = d+datetime.timedelta(days=1)
    S.msg = "dont disturb.."
    S.timestamp = d
    S.status = 'delivered'
    S.msg_type = 'text'
    S.user_id = 'ASMA'
    S.package_name = 'dhamaka'
    S.rates = 0.0
    S.target_network = 'ufone'  # process sms file would use it to send to respective network of which server is.
    S.client_type = 'smpp'
    DBSession.add(S)
    #user = DBSession.query(User_Number).filter_by(user_id='ASMA').first()  # user refers to normal user