| Line 141... |
Line 141... |
| 141 |
"""Yield successive n-sized chunks from l."""
|
141 |
"""Yield successive n-sized chunks from l."""
|
| 142 |
for i in xrange(0, len(l), n):
|
142 |
for i in xrange(0, len(l), n):
|
| 143 |
yield l[i:i+n]
|
143 |
yield l[i:i+n]
|
| 144 |
|
144 |
|
| 145 |
class __PushNotification:
|
145 |
class __PushNotification:
|
| 146 |
def __init__(self, notification_campaign_id, user_id, message, type, sms_type, sms_id, android_id, pushed_by, sent_timestamp, receive_timestamp, open_timestamp, sms_timestamp, gcm_id, created_timestamp, gcm_expired):
|
146 |
def __init__(self, notification_campaign_id, user_id, message, type, sms_type, sms_id, android_id, pushed_by, sent_timestamp, receive_timestamp, open_timestamp, sms_timestamp, gcm_id, created_timestamp, gcm_expired, notification_accounted):
|
| 147 |
self.notification_campaign_id = notification_campaign_id
|
147 |
self.notification_campaign_id = notification_campaign_id
|
| 148 |
self.user_id = user_id
|
148 |
self.user_id = user_id
|
| 149 |
self.message = message
|
149 |
self.message = message
|
| 150 |
self.type = type
|
150 |
self.type = type
|
| 151 |
self.sms_type = sms_type
|
151 |
self.sms_type = sms_type
|
| Line 156... |
Line 156... |
| 156 |
self.receive_timestamp = receive_timestamp
|
156 |
self.receive_timestamp = receive_timestamp
|
| 157 |
self.open_timestamp = open_timestamp
|
157 |
self.open_timestamp = open_timestamp
|
| 158 |
self.sms_timestamp = sms_timestamp
|
158 |
self.sms_timestamp = sms_timestamp
|
| 159 |
self.gcm_id = gcm_id
|
159 |
self.gcm_id = gcm_id
|
| 160 |
self.created_timestamp = created_timestamp
|
160 |
self.created_timestamp = created_timestamp
|
| 161 |
self.gcm_expired = gcm_expired
|
161 |
self.gcm_expired = gcm_expired
|
| - |
|
162 |
self.notification_accounted = notification_accounted
|
| 162 |
|
163 |
|
| 163 |
def getPendingCampaigns():
|
164 |
def getPendingCampaigns():
|
| 164 |
campaigns = list(get_mongo_connection(host=mongoHost).User.notificationcampaigns.find({'notification_processed':0,'expiresat':{'$gte':to_java_date(datetime.now())}}))
|
165 |
campaigns = list(get_mongo_connection(host=mongoHost).User.notificationcampaigns.find({'notification_processed':0,'expiresat':{'$gte':to_java_date(datetime.now())}}))
|
| 165 |
return campaigns
|
166 |
return campaigns
|
| 166 |
|
167 |
|
| Line 188... |
Line 189... |
| 188 |
user_list = []
|
189 |
user_list = []
|
| 189 |
for userId in userList:
|
190 |
for userId in userList:
|
| 190 |
user_list.append(userId)
|
191 |
user_list.append(userId)
|
| 191 |
|
192 |
|
| 192 |
for dataRec in result_data:
|
193 |
for dataRec in result_data:
|
| - |
|
194 |
'''
|
| 193 |
if str(dataRec[0]) in user_list:
|
195 |
if str(dataRec[0]) in user_list:
|
| 194 |
user_list.remove(str(dataRec[0]))
|
196 |
user_list.remove(str(dataRec[0]))
|
| - |
|
197 |
'''
|
| 195 |
if userGcmRegIdMap.has_key(dataRec[0]):
|
198 |
if userGcmRegIdMap.has_key(dataRec[0]):
|
| 196 |
detailMap = {}
|
199 |
detailMap = {}
|
| 197 |
gcmRegIdMap = userGcmRegIdMap.get(dataRec[0])
|
200 |
gcmRegIdMap = userGcmRegIdMap.get(dataRec[0])
|
| 198 |
detailMap['gcm_regid'] = dataRec[1]
|
201 |
detailMap['gcm_regid'] = dataRec[1]
|
| 199 |
if dataRec[3] is not None:
|
202 |
if dataRec[3] is not None:
|
| Line 266... |
Line 269... |
| 266 |
android_id = None
|
269 |
android_id = None
|
| 267 |
logging.debug("User Id:- "+str(userId)+" ..User Details:- "+str(details))
|
270 |
logging.debug("User Id:- "+str(userId)+" ..User Details:- "+str(details))
|
| 268 |
if details.has_key('android_id'):
|
271 |
if details.has_key('android_id'):
|
| 269 |
android_id = details['android_id']
|
272 |
android_id = details['android_id']
|
| 270 |
pushNotificationObj = __PushNotification(str(campaignId), long(userId), None, 'pending', \
|
273 |
pushNotificationObj = __PushNotification(str(campaignId), long(userId), None, 'pending', \
|
| 271 |
None, None, android_id, "php", None, None, None, None, gcm_id, to_java_date(datetime.now()),0)
|
274 |
None, None, android_id, "php", None, None, None, None, gcm_id, to_java_date(datetime.now()),0,0)
|
| 272 |
get_mongo_connection(host=mongoHost).User.pushnotifications.insert(pushNotificationObj.__dict__)
|
275 |
get_mongo_connection(host=mongoHost).User.pushnotifications.insert(pushNotificationObj.__dict__)
|
| 273 |
|
276 |
|
| 274 |
def populatePendingNotificationEntriesToBeSent():
|
277 |
def populatePendingNotificationEntriesToBeSent():
|
| 275 |
global pendingNotificationEntryMap
|
278 |
global pendingNotificationEntryMap
|
| 276 |
pendingNotificationEntries = list(get_mongo_connection(host=mongoHost).User.pushnotifications.find({'type':'pending'}))
|
279 |
pendingNotificationEntries = list(get_mongo_connection(host=mongoHost).User.pushnotifications.find({'type':'pending'}))
|