| Line 18... |
Line 18... |
| 18 |
import logging
|
18 |
import logging
|
| 19 |
from dtr.utils.utils import num_encode
|
19 |
from dtr.utils.utils import num_encode
|
| 20 |
|
20 |
|
| 21 |
PUSH_NOTIFICATIONS_DETAILS_URL="http://localhost:3001/getPushNotificationDetailsByType/?type=%s¬ification_campaign_id=%d&status=%s"
|
21 |
PUSH_NOTIFICATIONS_DETAILS_URL="http://localhost:3001/getPushNotificationDetailsByType/?type=%s¬ification_campaign_id=%d&status=%s"
|
| 22 |
PROMOTIONAL_SMS_SEND_URL = "http://103.15.179.45:8085/MessagingGateway/SendTransSMS?"
|
22 |
PROMOTIONAL_SMS_SEND_URL = "http://103.15.179.45:8085/MessagingGateway/SendTransSMS?"
|
| - |
|
23 |
TRANSACTIONAL_SMS_SEND_URL = "http://103.15.179.45:8085/SMSGateway/sendingSMS?"
|
| 23 |
#ID is: PRO02135496 Mobile Number is: 918512809859 PRO02135496#SMS Sent successfully to : 918512809859
|
24 |
#ID is: PRO02135496 Mobile Number is: 918512809859 PRO02135496#SMS Sent successfully to : 918512809859
|
| 24 |
#http://103.15.179.45:8085/MessagingGateway/http/querymsg?user=srlsaholicP&password=srp8oct&apimsgid=PRO02257518
|
25 |
#http://103.15.179.45:8085/MessagingGateway/http/querymsg?user=srlsaholicP&password=srp8oct&apimsgid=PRO02257518
|
| 25 |
#MessageID: PRO02135496 STATUS: DELIVRD ErrorCode: 0 DR Time: 2015-10-20 18:05:11
|
26 |
#MessageID: PRO02135496 STATUS: DELIVRD ErrorCode: 0 DR Time: 2015-10-20 18:05:11
|
| 26 |
|
27 |
|
| 27 |
DataService.initialize(db_hostname="192.168.158.89")
|
28 |
DataService.initialize(db_hostname="192.168.158.89")
|
| Line 61... |
Line 62... |
| 61 |
|
62 |
|
| 62 |
allUsers = Users.query.filter(Users.id.in_(tuple(userList))).all()
|
63 |
allUsers = Users.query.filter(Users.id.in_(tuple(userList))).all()
|
| 63 |
#print allUsers
|
64 |
#print allUsers
|
| 64 |
|
65 |
|
| 65 |
sentSmsUsers = []
|
66 |
sentSmsUsers = []
|
| 66 |
smsResponseIdMap = {}
|
67 |
proSmsResponseIdMap = {}
|
| - |
|
68 |
tranSmsResponseIdMap = {}
|
| 67 |
payloadList = []
|
69 |
payloadList = []
|
| 68 |
|
70 |
|
| 69 |
#smstext = str(notificationCampaign.messagetext) + ' http://bit.ly/1LBesWK'
|
71 |
#smstext = str(notificationCampaign.messagetext) + ' http://bit.ly/1LBesWK'
|
| 70 |
for user in allUsers:
|
72 |
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:
|
73 |
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.id) + '/' + num_encode(user.id)
|
74 |
smsUrl='http://pm1.in/A/' + num_encode(notificationCampaign.id) + '/' + num_encode(user.id)
|
| 73 |
smstext = str(notificationCampaign.messagetext) + ' ' + smsUrl
|
75 |
smstext = str(notificationCampaign.messagetext) + ' ' + smsUrl
|
| 74 |
#url_params = { 'Mobile' : '91'+user.mobile_number, 'Username' : 'srlsaholicP', 'Password' : 'srp8oct' , 'MessageType' : 'txt', 'SenderID' : '090000', 'Message' : notificationCampaign.messagetext }
|
76 |
#url_params = { 'Mobile' : '91'+user.mobile_number, 'Username' : 'srlsaholicP', 'Password' : 'srp8oct' , 'MessageType' : 'txt', 'SenderID' : '090000', 'Message' : notificationCampaign.messagetext }
|
| - |
|
77 |
url_params = ''
|
| - |
|
78 |
if "TRAN_SMS" in smstext:
|
| - |
|
79 |
url_params = { 'ani' : '91'+user.mobile_number, 'uname' : 'srlsaholic', 'passwd' : 'sr18mar' , 'cli' : 'PROFTM', 'message' : smstext }
|
| - |
|
80 |
else:
|
| 75 |
url_params = { 'Mobile' : '91'+user.mobile_number, 'Username' : 'srlsaholicP', 'Password' : 'srp8oct' , 'MessageType' : 'txt', 'SenderID' : '090000', 'Message' : smstext }
|
81 |
url_params = { 'Mobile' : '91'+user.mobile_number, 'Username' : 'srlsaholicP', 'Password' : 'srp8oct' , 'MessageType' : 'txt', 'SenderID' : '090000', 'Message' : smstext }
|
| 76 |
encoded_url_params = urllib.urlencode(url_params)
|
82 |
encoded_url_params = urllib.urlencode(url_params)
|
| 77 |
logging.debug('User Id:- '+str(user.id)+' Notification_Campaign_Id:- '+ str(notificationCampaign.id)+' Url Params:- '+str(encoded_url_params))
|
83 |
logging.debug('User Id:- '+str(user.id)+' Notification_Campaign_Id:- '+ str(notificationCampaign.id)+' Url Params:- '+str(encoded_url_params))
|
| - |
|
84 |
url = ''
|
| - |
|
85 |
if "TRAN_SMS" in smstext:
|
| - |
|
86 |
url = TRANSACTIONAL_SMS_SEND_URL + encoded_url_params
|
| - |
|
87 |
else:
|
| 78 |
url = PROMOTIONAL_SMS_SEND_URL + encoded_url_params
|
88 |
url = PROMOTIONAL_SMS_SEND_URL + encoded_url_params
|
| 79 |
response_str = None
|
89 |
response_str = None
|
| 80 |
try:
|
90 |
try:
|
| 81 |
req = urllib2.Request(url)
|
91 |
req = urllib2.Request(url)
|
| 82 |
response = urllib2.urlopen(req)
|
92 |
response = urllib2.urlopen(req)
|
| 83 |
response_str = response.read()
|
93 |
response_str = response.read()
|
| Line 102... |
Line 112... |
| 102 |
response = urllib2.urlopen(pushpostrequest, jsonObj).read()
|
112 |
response = urllib2.urlopen(pushpostrequest, jsonObj).read()
|
| 103 |
payloadList = []
|
113 |
payloadList = []
|
| 104 |
|
114 |
|
| 105 |
payloadList.append(payload)
|
115 |
payloadList.append(payload)
|
| 106 |
|
116 |
|
| - |
|
117 |
if "TRAN_SMS" in smstext:
|
| 107 |
if "mobile no in DND" in response_str:
|
118 |
if "Message sent successfully to " in response_str:
|
| - |
|
119 |
response_str_vals = response_str.split('#')
|
| - |
|
120 |
payload = {}
|
| - |
|
121 |
payload["user_id"]= user.id
|
| - |
|
122 |
payload["type"]="smsprocessed"
|
| - |
|
123 |
payload["notification_campaign_id"]= notificationCampaign.id
|
| - |
|
124 |
payload["status"]=1
|
| - |
|
125 |
payload["sms_id"]=response_str_vals[0]
|
| - |
|
126 |
payloadList.append(payload)
|
| - |
|
127 |
tranSmsResponseIdMap[user.id] = response_str_vals[0]
|
| - |
|
128 |
else:
|
| 108 |
payload = {}
|
129 |
payload = {}
|
| 109 |
payload["user_id"]= user.id
|
130 |
payload["user_id"]= user.id
|
| 110 |
payload["type"]="smsrejected"
|
131 |
payload["type"]="smsrejected"
|
| 111 |
payload["notification_campaign_id"]= notificationCampaign.id
|
132 |
payload["notification_campaign_id"]= notificationCampaign.id
|
| 112 |
payload["status"]=1
|
133 |
payload["status"]=1
|
| 113 |
payloadList.append(payload)
|
134 |
payloadList.append(payload)
|
| 114 |
else:
|
135 |
else:
|
| - |
|
136 |
if "mobile no in DND" in response_str:
|
| 115 |
payload = {}
|
137 |
payload = {}
|
| - |
|
138 |
payload["user_id"]= user.id
|
| - |
|
139 |
payload["type"]="smsrejected"
|
| - |
|
140 |
payload["notification_campaign_id"]= notificationCampaign.id
|
| - |
|
141 |
payload["status"]=1
|
| - |
|
142 |
payloadList.append(payload)
|
| - |
|
143 |
else:
|
| - |
|
144 |
payload = {}
|
| 116 |
payload["user_id"]= user.id
|
145 |
payload["user_id"]= user.id
|
| 117 |
payload["type"]="smsprocessed"
|
146 |
payload["type"]="smsprocessed"
|
| 118 |
payload["notification_campaign_id"]= notificationCampaign.id
|
147 |
payload["notification_campaign_id"]= notificationCampaign.id
|
| 119 |
payload["status"]=1
|
148 |
payload["status"]=1
|
| 120 |
|
149 |
|
| 121 |
|
150 |
|
| 122 |
response_vals = response_str.split('\n')
|
151 |
response_vals = response_str.split('\n')
|
| 123 |
logging.debug('Desired Response String:- '+str(response_vals[2]))
|
152 |
logging.debug('Desired Response String:- '+str(response_vals[2]))
|
| 124 |
if len(response_vals)==4 and 'SMS Sent successfully to' in response_vals[2]:
|
153 |
if len(response_vals)==4 and 'SMS Sent successfully to' in response_vals[2]:
|
| 125 |
if response_vals[2].split('#')[0]!='null':
|
154 |
if response_vals[2].split('#')[0]!='null':
|
| 126 |
smsResponseIdMap[user.id] = response_vals[2].split('#')[0]
|
155 |
proSmsResponseIdMap[user.id] = response_vals[2].split('#')[0]
|
| 127 |
payload["sms_id"]=response_vals[2].split('#')[0]
|
156 |
payload["sms_id"]=response_vals[2].split('#')[0]
|
| 128 |
payloadList.append(payload)
|
157 |
payloadList.append(payload)
|
| 129 |
sentSmsUsers.append(user.mobile_number)
|
158 |
sentSmsUsers.append(user.mobile_number)
|
| 130 |
|
159 |
|
| 131 |
time.sleep(120)
|
160 |
time.sleep(120)
|
| 132 |
|
161 |
|
| 133 |
for userId, msgId in smsResponseIdMap.items():
|
162 |
for userId, msgId in proSmsResponseIdMap.items():
|
| 134 |
#http://103.15.179.45:8085/MessagingGateway/http/querymsg?user=srlsaholicP&password=srp8oct&apimsgid=PRO02257518
|
163 |
#http://103.15.179.45:8085/MessagingGateway/http/querymsg?user=srlsaholicP&password=srp8oct&apimsgid=PRO02257518
|
| 135 |
del_det_params = {'user' : 'srlsaholicP', 'password' : 'srp8oct' , 'apimsgid' : msgId}
|
164 |
del_det_params = {'user' : 'srlsaholicP', 'password' : 'srp8oct' , 'apimsgid' : msgId}
|
| 136 |
encoded_del_det_params = urllib.urlencode(del_det_params)
|
165 |
encoded_del_det_params = urllib.urlencode(del_det_params)
|
| 137 |
del_det_url = 'http://103.15.179.45:8085/MessagingGateway/http/querymsg?' + encoded_del_det_params
|
166 |
del_det_url = 'http://103.15.179.45:8085/MessagingGateway/http/querymsg?' + encoded_del_det_params
|
| 138 |
logging.debug('Delivery Report Url:- '+del_det_url)
|
167 |
logging.debug('Delivery Report Url:- '+del_det_url)
|
| Line 172... |
Line 201... |
| 172 |
|
201 |
|
| 173 |
except Exception as e:
|
202 |
except Exception as e:
|
| 174 |
logging.debug('Error while getting response for message id:- '+ msgId)
|
203 |
logging.debug('Error while getting response for message id:- '+ msgId)
|
| 175 |
traceback.print_exc()
|
204 |
traceback.print_exc()
|
| 176 |
continue
|
205 |
continue
|
| - |
|
206 |
|
| - |
|
207 |
for userId, msgId in tranSmsResponseIdMap.items():
|
| - |
|
208 |
if msgId == "No_Response":
|
| - |
|
209 |
status = 'SMS_FAILED'
|
| - |
|
210 |
payload = {}
|
| - |
|
211 |
payload["user_id"]= userId
|
| - |
|
212 |
payload["type"]=status
|
| - |
|
213 |
payload["notification_campaign_id"]= notificationCampaign.id
|
| - |
|
214 |
payload["status"]=1
|
| - |
|
215 |
if len(payloadList)==5000:
|
| - |
|
216 |
jsonObj = json.dumps([dict(pn) for pn in payloadList])
|
| - |
|
217 |
pushpostrequest = urllib2.Request("http://localhost:3001/addPushNotification")
|
| - |
|
218 |
pushpostrequest.add_header('Content-Type', 'application/json')
|
| - |
|
219 |
response = urllib2.urlopen(pushpostrequest, jsonObj).read()
|
| - |
|
220 |
payloadList = []
|
| - |
|
221 |
payloadList.append(payload)
|
| - |
|
222 |
else:
|
| - |
|
223 |
del_det_params = {'uname' : 'srlsaholic', 'passwd' : 'sr18mar' , 'messageid' : msgId}
|
| - |
|
224 |
encoded_del_det_params = urllib.urlencode(del_det_params)
|
| - |
|
225 |
del_det_url = 'http://103.15.179.45:8085/SMSGateway/getApiReport?' + encoded_del_det_params
|
| - |
|
226 |
logging.debug('Delivery Report Url:- '+del_det_url)
|
| - |
|
227 |
try:
|
| - |
|
228 |
del_req = urllib2.Request(del_det_url)
|
| - |
|
229 |
del_response = urllib2.urlopen(del_req)
|
| - |
|
230 |
del_response_str = del_response.read()
|
| - |
|
231 |
logging.debug('Delivery Report Response:- '+str(del_response_str))
|
| - |
|
232 |
|
| - |
|
233 |
del_response_vals = del_response_str.split(' ')
|
| - |
|
234 |
|
| - |
|
235 |
status = ''
|
| - |
|
236 |
if len(del_response_vals) == 8 and del_response_vals[7][:-2] == '0':
|
| - |
|
237 |
status = 'SMS_DELIVRD'
|
| - |
|
238 |
elif "Submitted to SMSC" in del_response_str:
|
| - |
|
239 |
status = 'SMS_INPROCESS'
|
| - |
|
240 |
else:
|
| - |
|
241 |
status = 'SMS_FAILED'
|
| - |
|
242 |
payload = {}
|
| - |
|
243 |
payload["user_id"]= userId
|
| - |
|
244 |
payload["type"]=status
|
| - |
|
245 |
payload["notification_campaign_id"]= notificationCampaign.id
|
| - |
|
246 |
payload["status"]=1
|
| - |
|
247 |
if len(payloadList)==5000:
|
| - |
|
248 |
jsonObj = json.dumps([dict(pn) for pn in payloadList])
|
| - |
|
249 |
pushpostrequest = urllib2.Request("http://localhost:3001/addPushNotification")
|
| - |
|
250 |
pushpostrequest.add_header('Content-Type', 'application/json')
|
| - |
|
251 |
response = urllib2.urlopen(pushpostrequest, jsonObj).read()
|
| - |
|
252 |
payloadList = []
|
| - |
|
253 |
payloadList.append(payload)
|
| - |
|
254 |
|
| - |
|
255 |
except Exception as e:
|
| - |
|
256 |
logging.debug('Error while getting response for message id:- '+ msgId)
|
| - |
|
257 |
traceback.print_exc()
|
| - |
|
258 |
continue
|
| - |
|
259 |
|
| - |
|
260 |
|
| 177 |
|
261 |
|
| 178 |
jsonObj = json.dumps([dict(pn) for pn in payloadList])
|
262 |
jsonObj = json.dumps([dict(pn) for pn in payloadList])
|
| 179 |
pushpostrequest = urllib2.Request("http://localhost:3001/addPushNotification")
|
263 |
pushpostrequest = urllib2.Request("http://localhost:3001/addPushNotification")
|
| 180 |
pushpostrequest.add_header('Content-Type', 'application/json')
|
264 |
pushpostrequest.add_header('Content-Type', 'application/json')
|
| 181 |
response = urllib2.urlopen(pushpostrequest, jsonObj).read()
|
265 |
response = urllib2.urlopen(pushpostrequest, jsonObj).read()
|