def save_sms(): sms = request.args['sms'] fullsms = request.args['fullsms'] route = request.args['route'] sender = request.args['sender'] text = Sms(sms=sms, fullsms=fullsms, route=route, sender=sender) text.save() return json.dumps({'success': True}), 200, { 'ContentType': 'application/json' }
def sms_list_data(): val = redis.rpop("sms_list") while(val is not None) : json_obj = json.loads(val) mobile_no = json_obj['mobile_no'] if type(mobile_no) is unicode: mobile_no = mobile_no.split(',') message_type = json_obj['message_type'] message = json_obj['message'] send_sms(mobile_no, message) s = Sms(message=message,message_type = message_type, mobile = mobile_no) s.save() val = redis.rpop("sms_list") return val
def sms_list_data(): val = redis.rpop("sms_list") while (val is not None): json_obj = json.loads(val) mobile_no = json_obj['mobile_no'] if type(mobile_no) is unicode: mobile_no = mobile_no.split(',') message_type = json_obj['message_type'] message = json_obj['message'] send_sms(mobile_no, message) s = Sms(message=message, message_type=message_type, mobile=mobile_no) s.save() val = redis.rpop("sms_list") return val
def the_sms(): sms = Sms.select() text = [] for s in sms: if len(s.sender) > 5: if not "MOVISTAR" in s.sender: if not "Movistar te informa" in s.fullsms: words = re.findall(r'\w+', s.fullsms.lower()) s.cm = Counter(words).most_common(10) text.append(s) text.reverse() return flask.render_template('sms.html', sms=text)
def read_and_store_sms(sms_file): f = open(sms_file, mode='r') line_id = None line_number = 0 for current_line in f: try: line_number += 1 if len(current_line) <= 1: continue # this line is a new sms if current_line.strip().startswith("sms"): # split may contain more than we want because of the comma in content spited = current_line.split(",") direction, name, phone, date_time, content = spited[1], spited[2], spited[3], spited[5], spited[7], date_time = deal_with_sms_date_time(date_time) # the position of name and phone may exchange due to the direction if direction == "submit": pass else: name, phone = phone, name sp_list = [direction, name, phone, date_time, content] tp_list = [] for a in sp_list: tp_list.append(a.strip()) new_sms = Sms(sms_direction=tp_list[0], sms_name=tp_list[1], sms_phone=tp_list[2], sms_date=tp_list[3][:10], sms_time=tp_list[3], sms_content=tp_list[4]) new_sms.save() line_id = new_sms.get_id() continue # this line is a continue content if line_id is None: continue sms = Sms.get(id=line_id) sms.sms_content += current_line sms.save() except Exception, e: ErrorLog(error_line=line_number, error_function="read_and_store_sms", error_msg=e).save()
def generate_sms(self, bill_start_day): """ 根据指定的日期, 获取指定的短信记录 :param bill_start_day: :return: """ sms = json.loads(Sms.objects(mobile=self.phone, time__gte=bill_start_day).to_json()) for item in sms: del item["_id"] del item["task_id"] del item["mobile"] return sms
def read_and_store_sms(sms_file): f = open(sms_file, mode='r') line_id = None line_number = 0 for current_line in f: try: line_number += 1 if len(current_line) <= 1: continue # this line is a new sms if current_line.strip().startswith("sms"): # split may contain more than we want because of the comma in content spited = current_line.split(",") direction, name, phone, date_time, content = spited[1], spited[ 2], spited[3], spited[5], spited[7], date_time = deal_with_sms_date_time(date_time) # the position of name and phone may exchange due to the direction if direction == "submit": pass else: name, phone = phone, name sp_list = [direction, name, phone, date_time, content] tp_list = [] for a in sp_list: tp_list.append(a.strip()) new_sms = Sms(sms_direction=tp_list[0], sms_name=tp_list[1], sms_phone=tp_list[2], sms_date=tp_list[3][:10], sms_time=tp_list[3], sms_content=tp_list[4]) new_sms.save() line_id = new_sms.get_id() continue # this line is a continue content if line_id is None: continue sms = Sms.get(id=line_id) sms.sms_content += current_line sms.save() except Exception, e: ErrorLog(error_line=line_number, error_function="read_and_store_sms", error_msg=e).save()
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)
from models import User, Sms, Selected_package, User_Number, Prefix_Match 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)