| Line 35... |
Line 35... |
| 35 |
logging.debug('Starting SMS Blaster Process.....'+str(datetime.now()))
|
35 |
logging.debug('Starting SMS Blaster Process.....'+str(datetime.now()))
|
| 36 |
timeCondition = datetime.now()-timedelta(hours=2)
|
36 |
timeCondition = datetime.now()-timedelta(hours=2)
|
| 37 |
expireTimeCondition = datetime.now()+timedelta(hours=2)
|
37 |
expireTimeCondition = datetime.now()+timedelta(hours=2)
|
| 38 |
eligibleSmsNotficationCampaigns = list(get_mongo_connection(host=mongoHost).User.notificationcampaigns.find({'notification_processed':1, 'sendsms':1, 'smsprocessed':0,'created':{'$lte':to_java_date(timeCondition)}, 'expiresat':{'$gte':to_java_date(expireTimeCondition)}}))
|
38 |
eligibleSmsNotficationCampaigns = list(get_mongo_connection(host=mongoHost).User.notificationcampaigns.find({'notification_processed':1, 'sendsms':1, 'smsprocessed':0,'created':{'$lte':to_java_date(timeCondition)}, 'expiresat':{'$gte':to_java_date(expireTimeCondition)}}))
|
| 39 |
for notificationCampaign in eligibleSmsNotficationCampaigns:
|
39 |
for notificationCampaign in eligibleSmsNotficationCampaigns:
|
| 40 |
logging.debug('Notification_Campign_Id:- '+str(notificationCampaign.id))
|
40 |
logging.debug('Notification_Campign_Id:- '+str(notificationCampaign.get('_id')))
|
| 41 |
get_mongo_connection(host=mongoHost).User.notificationcampaigns.update({'_id':notificationCampaign.get('_id')},{"$set":{'smsprocessed':1}})
|
41 |
get_mongo_connection(host=mongoHost).User.notificationcampaigns.update({'_id':notificationCampaign.get('_id')},{"$set":{'smsprocessed':1}})
|
| 42 |
pushnotifications = list(get_mongo_connection(host=mongoHost).User.pushnotificationsnew.find({'notification_campaign_id':notificationCampaign.get('_id')}))
|
42 |
pushnotifications = list(get_mongo_connection(host=mongoHost).User.pushnotifications.find({'notification_campaign_id':str(notificationCampaign.get('_id'))}))
|
| 43 |
pushnotificationUsersMap = {}
|
43 |
pushnotificationUsersMap = {}
|
| 44 |
notificationSuccessUsers = []
|
44 |
notificationSuccessUsers = []
|
| 45 |
smsToBeSentUsersMap = {}
|
45 |
smsToBeSentUsersMap = {}
|
| 46 |
for entry in pushnotifications:
|
46 |
for entry in pushnotifications:
|
| 47 |
if str(entry.get('type'))!='sent' and entry.get('user_id') not in notificationSuccessUsers:
|
47 |
if str(entry.get('type'))!='sent' and entry.get('user_id') not in notificationSuccessUsers:
|
| Line 67... |
Line 67... |
| 67 |
proSmsResponseIdMap = {}
|
67 |
proSmsResponseIdMap = {}
|
| 68 |
tranSmsResponseIdMap = {}
|
68 |
tranSmsResponseIdMap = {}
|
| 69 |
|
69 |
|
| 70 |
for user in allUsers:
|
70 |
for user in allUsers:
|
| 71 |
if user.mobile_number is not None and len(user.mobile_number)==10 and user.mobile_number not in sentSmsUsers:
|
71 |
if user.mobile_number is not None and len(user.mobile_number)==10 and user.mobile_number not in sentSmsUsers:
|
| 72 |
smsUrl='http://pm1.in/A/' + num_encode(notificationCampaign.get('id')) + '/' + num_encode(user.id)
|
72 |
smsUrl='http://pm1.in/A/' + num_encode(str(notificationCampaign.get('_id'))) + '/' + num_encode(user.id)
|
| 73 |
smstext = str(notificationCampaign.get('messagetext')) + ' ' + smsUrl
|
73 |
smstext = str(notificationCampaign.get('messagetext')) + ' ' + smsUrl
|
| 74 |
#url_params = { 'Mobile' : '91'+user.mobile_number, 'Username' : 'srlsaholicP', 'Password' : 'srp8oct' , 'MessageType' : 'txt', 'SenderID' : '090000', 'Message' : notificationCampaign.messagetext }
|
74 |
#url_params = { 'Mobile' : '91'+user.mobile_number, 'Username' : 'srlsaholicP', 'Password' : 'srp8oct' , 'MessageType' : 'txt', 'SenderID' : '090000', 'Message' : notificationCampaign.messagetext }
|
| 75 |
url_params = ''
|
75 |
url_params = ''
|
| 76 |
if "TRAN_SMS" in smstext:
|
76 |
if "TRAN_SMS" in smstext:
|
| 77 |
url_params = { 'ani' : '91'+user.mobile_number, 'uname' : 'srlsaholic', 'passwd' : 'sr18mar' , 'cli' : 'PROFTM', 'message' : smstext.replace("TRAN_SMS", "").strip() }
|
77 |
url_params = { 'ani' : '91'+user.mobile_number, 'uname' : 'srlsaholic', 'passwd' : 'sr18mar' , 'cli' : 'PROFTM', 'message' : smstext.replace("TRAN_SMS", "").strip() }
|
| Line 94... |
Line 94... |
| 94 |
traceback.print_exc()
|
94 |
traceback.print_exc()
|
| 95 |
continue
|
95 |
continue
|
| 96 |
|
96 |
|
| 97 |
entry = smsToBeSentUsersMap.get(user.id)
|
97 |
entry = smsToBeSentUsersMap.get(user.id)
|
| 98 |
logging.debug('User Id:- '+str(user.id)+' Notification_Campaign_Id:- '+ str(notificationCampaign.get('_id'))+' Sent Response:- '+ str(response_str))
|
98 |
logging.debug('User Id:- '+str(user.id)+' Notification_Campaign_Id:- '+ str(notificationCampaign.get('_id'))+' Sent Response:- '+ str(response_str))
|
| 99 |
get_mongo_connection(host=mongoHost).User.pushnotificationsnew.update({'_id':entry.get('_id')},{"$set":{'smstype':'smssent','sms_timestamp':to_java_date(datetime.now())}})
|
99 |
get_mongo_connection(host=mongoHost).User.pushnotifications.update({'_id':entry.get('_id')},{"$set":{'smstype':'smssent','sms_timestamp':to_java_date(datetime.now())}})
|
| 100 |
if "TRAN_SMS" in smstext:
|
100 |
if "TRAN_SMS" in smstext:
|
| 101 |
if "Message sent successfully to " in response_str:
|
101 |
if "Message sent successfully to " in response_str:
|
| 102 |
response_str_vals = response_str.split('#')
|
102 |
response_str_vals = response_str.split('#')
|
| 103 |
get_mongo_connection(host=mongoHost).User.pushnotificationsnew.update({'_id':entry.get('_id')},{"$set":{'smstype':'smsprocessed','sms_timestamp':to_java_date(datetime.now()),'sms_id':response_str_vals[0]}})
|
103 |
get_mongo_connection(host=mongoHost).User.pushnotifications.update({'_id':entry.get('_id')},{"$set":{'smstype':'smsprocessed','sms_timestamp':to_java_date(datetime.now()),'sms_id':response_str_vals[0]}})
|
| 104 |
tranSmsResponseIdMap[user.id] = response_str_vals[0]
|
104 |
tranSmsResponseIdMap[user.id] = response_str_vals[0]
|
| 105 |
else:
|
105 |
else:
|
| 106 |
get_mongo_connection(host=mongoHost).User.pushnotificationsnew.update({'_id':entry.get('_id')},{"$set":{'smstype':'smsrejected','sms_timestamp':to_java_date(datetime.now())}})
|
106 |
get_mongo_connection(host=mongoHost).User.pushnotifications.update({'_id':entry.get('_id')},{"$set":{'smstype':'smsrejected','sms_timestamp':to_java_date(datetime.now())}})
|
| 107 |
else:
|
107 |
else:
|
| 108 |
if "mobile no in DND" in response_str:
|
108 |
if "mobile no in DND" in response_str:
|
| 109 |
get_mongo_connection(host=mongoHost).User.pushnotificationsnew.update({'_id':entry.get('_id')},{"$set":{'smstype':'smsrejected','sms_timestamp':to_java_date(datetime.now())}})
|
109 |
get_mongo_connection(host=mongoHost).User.pushnotifications.update({'_id':entry.get('_id')},{"$set":{'smstype':'smsrejected','sms_timestamp':to_java_date(datetime.now())}})
|
| 110 |
else:
|
110 |
else:
|
| 111 |
response_vals = response_str.split('\n')
|
111 |
response_vals = response_str.split('\n')
|
| 112 |
logging.debug('Desired Response String:- '+str(response_vals[2]))
|
112 |
logging.debug('Desired Response String:- '+str(response_vals[2]))
|
| 113 |
if len(response_vals)==4 and 'SMS Sent successfully to' in response_vals[2]:
|
113 |
if len(response_vals)==4 and 'SMS Sent successfully to' in response_vals[2]:
|
| 114 |
if response_vals[2].split('#')[0]!='null':
|
114 |
if response_vals[2].split('#')[0]!='null':
|
| 115 |
proSmsResponseIdMap[user.id] = response_vals[2].split('#')[0]
|
115 |
proSmsResponseIdMap[user.id] = response_vals[2].split('#')[0]
|
| 116 |
get_mongo_connection(host=mongoHost).User.pushnotificationsnew.update({'_id':entry.get('_id')},{"$set":{'smstype':'smsprocessed','sms_timestamp':to_java_date(datetime.now()),'sms_id':response_vals[2].split('#')[0]}})
|
116 |
get_mongo_connection(host=mongoHost).User.pushnotifications.update({'_id':entry.get('_id')},{"$set":{'smstype':'smsprocessed','sms_timestamp':to_java_date(datetime.now()),'sms_id':response_vals[2].split('#')[0]}})
|
| 117 |
|
117 |
|
| 118 |
sentSmsUsers.append(user.mobile_number)
|
118 |
sentSmsUsers.append(user.mobile_number)
|
| 119 |
|
119 |
|
| 120 |
time.sleep(30)
|
120 |
time.sleep(30)
|
| 121 |
|
121 |
|
| Line 141... |
Line 141... |
| 141 |
elif 'EXP_' in status:
|
141 |
elif 'EXP_' in status:
|
| 142 |
status = 'SMS_EXPIRED'
|
142 |
status = 'SMS_EXPIRED'
|
| 143 |
else:
|
143 |
else:
|
| 144 |
status = 'SMS_'+status
|
144 |
status = 'SMS_'+status
|
| 145 |
entry = smsToBeSentUsersMap.get(userId)
|
145 |
entry = smsToBeSentUsersMap.get(userId)
|
| 146 |
get_mongo_connection(host=mongoHost).User.pushnotificationsnew.update({'_id':entry.get('_id')},{"$set":{'smstype':status,'sms_timestamp':to_java_date(datetime.now())}})
|
146 |
get_mongo_connection(host=mongoHost).User.pushnotifications.update({'_id':entry.get('_id')},{"$set":{'smstype':status,'sms_timestamp':to_java_date(datetime.now())}})
|
| 147 |
except Exception as e:
|
147 |
except Exception as e:
|
| 148 |
logging.debug('Error while getting response for message id:- '+ msgId)
|
148 |
logging.debug('Error while getting response for message id:- '+ msgId)
|
| 149 |
traceback.print_exc()
|
149 |
traceback.print_exc()
|
| 150 |
continue
|
150 |
continue
|
| 151 |
|
151 |
|
| Line 178... |
Line 178... |
| 178 |
except Exception as e:
|
178 |
except Exception as e:
|
| 179 |
logging.debug('Error while getting response for message id:- '+ msgId)
|
179 |
logging.debug('Error while getting response for message id:- '+ msgId)
|
| 180 |
traceback.print_exc()
|
180 |
traceback.print_exc()
|
| 181 |
continue
|
181 |
continue
|
| 182 |
|
182 |
|
| 183 |
get_mongo_connection(host=mongoHost).User.pushnotificationsnew.update({'_id':entry.get('_id')},{"$set":{'smstype':status,'sms_timestamp':to_java_date(datetime.now())}})
|
183 |
get_mongo_connection(host=mongoHost).User.pushnotifications.update({'_id':entry.get('_id')},{"$set":{'smstype':status,'sms_timestamp':to_java_date(datetime.now())}})
|
| 184 |
|
184 |
|
| 185 |
logging.debug('Total Sms Sent:- '+str(len(sentSmsUsers)))
|
185 |
logging.debug('Total Sms Sent:- '+str(len(sentSmsUsers)))
|
| 186 |
logging.debug('SMS Blaster Process Completed.....'+str(datetime.now()))
|
186 |
logging.debug('SMS Blaster Process Completed.....'+str(datetime.now()))
|
| 187 |
|
187 |
|
| 188 |
|
188 |
|